Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when inserting values via prepared statements, bound integer value to char column [ODBC139] #136

Closed
firebird-automations opened this issue Feb 15, 2012 · 5 comments

Comments

@firebird-automations
Copy link

Submitted by: Sven Steinseifer (svensteinseifer)

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.

Commits: b994cee 6122325

@firebird-automations
Copy link
Author

Commented by: @alexpotapchenko

Fixed in CVS

@firebird-automations
Copy link
Author

Modified by: @alexpotapchenko

status: Open [ 1 ] => Resolved [ 5 ]

resolution: Fixed [ 1 ]

Fix Version: 2.0.1 [ 10430 ]

@firebird-automations
Copy link
Author

Commented by: Sven Steinseifer (svensteinseifer)

Thanks!

@firebird-automations
Copy link
Author

Commented by: Sven Steinseifer (svensteinseifer)

It works!

@firebird-automations
Copy link
Author

Modified by: @alexpotapchenko

status: Resolved [ 5 ] => Closed [ 6 ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants