Issue Details (XML | Word | Printable)

Key: ODBC-139
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Critical Critical
Assignee: Alexander Potapchenko
Reporter: Sven Steinseifer
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
ODBC Driver

Crash when inserting values via prepared statements, bound integer value to char column

Created: 15/Feb/12 12:12 PM   Updated: 31/May/12 03:27 PM
Component/s: None
Affects Version/s: 2.0
Fix Version/s: 2.0.1

Environment: Windows 7


 Description  « Hide
A crash occures in the Firebird odbc driver when I execute the following statements:

r = SQLPrepare(hstmt, (SQLCHAR*)"INSERT INTO test (id, text) VALUES (1, ?)", SQL_NTS); // test.text is a CHAR column

int value = 1;
r = SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &value, 0, 0); // binds INTEGER value to CHAR column

r = SQLExecute(hstmt); // crashs


A debugging session revealed that the crash occurres in
OdbcConvert::conv##TYPE_FROM##ToString(DescRecord * from, DescRecord * to)
when the ODBCCONVERT_CHECKNULL macro gets called.
The indicatorFrom variable has a 0 value (from last parameter of SQLBindParameter, which is valid according to MSDN) and gets dereferenced in this macro:

#define ODBCCONVERT_CHECKNULL(pointerTo) \
if( *(short*)indicatorFrom == SQL_NULL_DATA ) \
{ \
if ( indicatorTo ) \
*indicatorTo = SQL_NULL_DATA; \
if ( pointerTo ) \
*(char*)pointerTo = 0; \
return SQL_SUCCESS; \
} \
if ( !pointerTo ) \
return SQL_SUCCESS;

If I change this to the following, the crash disappears:
#define ODBCCONVERT_CHECKNULL(pointerTo) \
if( indicatorFrom && *(short*)indicatorFrom == SQL_NULL_DATA ) \
{ \
if ( indicatorTo ) \
*indicatorTo = SQL_NULL_DATA; \
if ( pointerTo ) \
*(char*)pointerTo = 0; \
return SQL_SUCCESS; \
} \
if ( !pointerTo ) \
return SQL_SUCCESS;

Because this macro is used very often, I cannot be sure, if this doesn't introduce some other bugs.

 All   Comments   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
There are no subversion log entries for this issue yet.