mdbtools: [PATCH] Fixes in odbc.c to return size of returned strings and handle OLE data
Package: mdbtools
Version: 0.5.99.0.6pre1.0.20051109-4
Severity: important
*** Please type your report below this line ***
Attached a patch that fixes several issues in odbc.c that have been found
while using libmdbodbc.so with the OGR PGeo driver of the GDAL package.
- SQLDescribeCol doesn't return the string length in *pcbColName, which
breaks CPLODBCStatement::CollectResultsInfo() in port/cpl_odbc.cpp in
GDAL that uses that value to force a '\0' character at the end of the
string
- SQLColAttributes doesn't return the string length in *pcbDesc, which
breaks CPLODBCStatement::CollectResultsInfo() in port/cpl_odbc.cpp in
GDAL that uses that value to force a '\0' character at the end of the
string
- SQLGetData doesn't return the correct string length in *pcbValue. It
should return strlen(rgbValue) instead of col->cur_value_len which is
sometimes < strlen(rgbValue). That breaks CPLODBCStatement::Fetch in
port/cpl_odbc.cpp that uses that value to force a '\0' character at
the end of the string
- SQLGetData doesn't handle correctly OLE data type, which prevents the
OGR PGeo driver from retrieving the geometry data
-- System Information:
Debian Release: lenny/sid
APT prefers hardy-updates
APT policy: (500, 'hardy-updates'), (500, 'hardy-security'),
(500, 'hardy-proposed'), (500, 'hardy-backports'), (500, 'hardy')
Architecture: i386 (i686)
Kernel: Linux 2.6.24-21-386
Locale: LANG=fr_FR.UTF-8, LC_CTYPE=fr_FR.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Versions of packages mdbtools depends on:
ii libc6 2.7-10ubuntu4 GNU C Library: Shared libraries
ii libglib2.0-0 2.16.6-0ubuntu1 The GLib library of C routines
ii libmdbtools 0.5.99.0.6pre1.0.20051109-4 mdbtools libraries
ii libreadline5 5.2-3build1 GNU readline and history
libraries
mdbtools recommends no packages.
-- no debconf information
--- mdbtools-0.5.99.0.6pre1.0.20051109.ori/src/odbc/odbc.c 2005-04-09 13:17:56.000000000 +0200
+++ mdbtools-0.5.99.0.6pre1.0.20051109/src/odbc/odbc.c 2008-11-23 16:25:35.000000000 +0100
@@ -623,6 +623,8 @@
namelen = MIN(cbColNameMax,strlen(sqlcol->name));
strncpy(szColName, sqlcol->name, namelen);
szColName[namelen]='\0';
+ if (pcbColName)
+ *pcbColName = namelen;
}
if (pfSqlType) {
*pfSqlType = _odbc_get_client_type(col->col_type);
@@ -693,6 +695,8 @@
namelen = MIN(cbDescMax,strlen(sqlcol->name));
strncpy(rgbDesc, sqlcol->name, namelen);
((char *)rgbDesc)[namelen]='\0';
+ if (pcbDesc)
+ *pcbDesc = namelen;
break;
case SQL_COLUMN_TYPE:
*pfDesc = SQL_CHAR;
@@ -1162,13 +1166,20 @@
strcpy(rgbValue, (col->cur_value_len)?"0":"1");
if (pcbValue)
*pcbValue = 1;
+ } else if (col->col_type == MDB_OLE) {
+ int len;
+ col->bind_ptr = rgbValue;
+ len = mdb_ole_read(mdb, col, mdb->pg_buf + col->cur_value_start, cbValueMax);
+ col->bind_ptr = NULL;
+ if (pcbValue)
+ *pcbValue = len;
} else if (col->cur_value_len) {
char *str = mdb_col_to_string(mdb,mdb->pg_buf,
col->cur_value_start,col->col_type,col->cur_value_len);
- strcpy(rgbValue, str);
+ strncpy(rgbValue, str, cbValueMax);
g_free(str);
if (pcbValue)
- *pcbValue = col->cur_value_len;
+ *pcbValue = strlen(rgbValue);
} else {
/* When NULL data is retrieved, non-null pcbValue is required */
if (pcbValue) {
Reply to: