MySQL Forums
Forum List  »  Connector/C++

C++ Connector/Corruption when using Prepared Statement
Posted by: Marius-Paul Dumitrean
Date: December 23, 2017 05:45AM

I have been hunting down a memory corruption issue with the results of C++/Connector for the last couple of days.

The issue really only shows up when using a prepared statement, and the resul is of type MYSQL_TYPE_VAR_STRING > 64 bytes in length. In my case the result was 70 characters in length and would get corrupted after the 64th byte.

I have narrowed down the bug to here -
mysql_resultbind.cpp in allocate_buffer_for_field():

return st_buffer_size_type(new char[field->max_length + 1], field->max_length + 1, field->type);
#endif //LIBMYSQL_VERSION_ID > 50700

For some reason LIBMYSQL_VERSION_ID is not set at all at this point (but MYSQL_VERSION_ID) is. I haven't figured out why its not set yet...

So the switch falls thru to MYSQL_TYPE_DECIMAL and allocates a fixed 64 bytes.
This behavior does not seem correct, why would a VAR_STRING ever fall through to a fixed 64 bytes?

I feel like the return statement should be outside of the #if/#endif and it is a bug having it inside the #if statement.

Can one of the developers elaborate?

Options: ReplyQuote

Written By
C++ Connector/Corruption when using Prepared Statement
December 23, 2017 05:45AM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.