Bug #11038 Program crashes when connecting to MySQL server
Submitted: 2 Jun 2005 14:52 Modified: 8 Aug 2005 16:01
Reporter: Mercier Raymond Email Updates:
Status: Not a Bug Impact on me:
None 
Category:Connector / ODBC Severity:S3 (Non-critical)
Version:MyODBC-3.51.10-x86-win-32bit.exe OS:Windows (Windows XP SP2)
Assigned to: Sergey Vlasenko CPU Architecture:Any

[2 Jun 2005 14:52] Mercier Raymond
Description:
My program is a UNICODE program and I use SQLDriverConnectW() to connect to the database.

How to repeat:
I use a buffer to receive the returned string by the call

char In = L"any valid connection string";
char out[1024];
SQLSMALLINT outlen;

ret = SQLDriverConnect(dbc, NULL, In, _tcslen(In), Out, sizeof(Out), &outlen, SQL_DRIVER_NOPROMPT);
this call will crash (access violation)

ret = SQLDriverConnect(dbc, NULL, In, _tcslen(In), Out, sizeof(Out)/Sizeof(Out[0]), &outlen, SQL_DRIVER_NOPROMPT);
this call will not crash

Suggested fix:
I think the problem is in the size of the buffer (parameter 6).

The microsoft documentation says that this parameter is "Length of the *OutConnectionString buffer. If the *OutConnectionString value is a Unicode string (when calling SQLDriverConnectW), the BufferLength argument must be an even number. "

Microsoft seem to says (but maybe I'm wrong) that this size is a size in bytes and not in unicode char

in my code I had sizeof(Out). This make the program to crash
to avoid the crash, I need to write sizeof(Out) / sizeof(Out[0])

I hope it will help you
Raymond.Mercier@libertysurf.fr
[3 Jun 2005 1:18] MySQL Verification Team
Could you please provide a test case (code) and the
database schema with data.?

Thanks in advance.
[3 Jun 2005 8:00] Vasily Kishkin
I created test case and tried to reproduce the bug. All worked fine. I attached my case test. Could you look my case test ? 
The result of test case:
D:\STORE ODBC FILES\11038>test.exe
Size of char: 2 , Value of In: DRIVER=MySQL ODBC 3.51 Driver;
Connect 1....
Connect 2....
Free....
[3 Jun 2005 8:00] Vasily Kishkin
Test case

Attachment: 11038.zip (application/x-zip-compressed, text), 2.45 KiB.

[3 Jun 2005 8:03] Mercier Raymond
VC 6.0 project to show the bug

Attachment: Bug_rm.zip (application/x-zip-compressed, text), 6.46 KiB.

[3 Jun 2005 8:06] Mercier Raymond
I just added a program test (Bug_rm.zip) that crashed every timer in debug mode

enjoy it :-)
Raymond
[8 Jun 2005 5:45] Jorge del Conde
Hi,

I was able to reproduce this bug using bug_rm.  Also, the API usage looks right.

Marking bug as verified!
[8 Aug 2005 16:01] Sergey Vlasenko
Not a bug. For explanation of "Length Arguments for Unicode ODBC Functions" refer to Microsoft KB article KB294169.