Skip to content

[2 patches] ODBC SQL driver: fix conversion of QByteArray to QVLA<SQLTCHAR> / SQL/ODBC: Pass correct length to SQLColAttribute()

ODBC SQL driver: fix conversion of QByteArray to QVLA

The QByteArray is assumed to contain an SQLTCHAR string (so, either UTF-8, UTF-16 or UTF-32-encoded). Only in the UTF-8 case would the size of the byte array be the same as the size of the SQLTCHAR string in codepoints, yet the size in bytes is what the code passed to the QVLA append() call, causing it to read past the QByteArray buffer in the UTF-16 and UTF-32 cases.

Fix by properly calculating the string size from the size-in-bytes and then memcpy()ing into the QVLA. We use memcpy() and not QVLA::append(T*, n) because the QByteArray buffer need not be aligned on an alignof(SQLTCHAR) boundary (certainly not since it gained the prepend "optimization").

Pick-to: 6.5 6.4 6.2 5.15 Change-Id: If3838c3dee89e6aca65541242642315b8e1fa6b4 Reviewed-by: Thiago Macieira thiago.macieira@intel.com (cherry picked from commit 4c445ef0)

SQL/ODBC: Pass correct length to SQLColAttribute()

This ensures the tst_QSqlQuery::record() test passes when checking the tablename.

Pick-to: 6.5 6.4 6.2 5.15 Change-Id: I146f9f627ea366c6813af61ce48b930ca1041b15 Reviewed-by: Thiago Macieira thiago.macieira@intel.com (cherry picked from commit 9ea00c70)

Edited by Andreas Sturmlechner

Merge request reports