diff options
author | Marc Mutz <marc.mutz@qt.io> | 2023-03-20 12:33:02 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2023-03-21 18:40:50 +0000 |
commit | 9020034b3b6a3a8118e5959beed699bb8aaa3f95 (patch) | |
tree | 390d60729eb1ace87bbc7323a7808ac0504f6406 /src/plugins/sqldrivers/odbc/qsql_odbc.cpp | |
parent | 29b55dcb830ad5f6f12a8918d267efca33d3af61 (diff) |
QSQL/ODBC: fix regression (trailing NUL)
When we fixed the callers of toSQLTCHAR() to use the result's size()
instead of the input's (which differ, if sizeof(SQLTCHAR) != 2), we
exposed callers to the append(0), which changes the size() of the
result QVLA. Callers that don't rely on NUL-termination (all?) now saw
an additional training NUL.
Fix by not NUL-terminating, and changing the only user of SQL_NTS to
use an explicit length.
Amends 4c445ef0bae8b36ec4a742552f0ebd81a1a90723 and
46af1fe49f7f419dc1b3231de9860e2da0ea48f8.
Done-with: Christian Ehrlicher <ch.ehrlicher@gmx.de>
Pick-to: 6.5 6.5.0 6.4 6.2 5.15
Change-Id: I6210b77e9417f46294df94cb32ab4134af8dc4c2
Reviewed-by: Andy Shaw <andy.shaw@qt.io>
Diffstat (limited to 'src/plugins/sqldrivers/odbc/qsql_odbc.cpp')
-rw-r--r-- | src/plugins/sqldrivers/odbc/qsql_odbc.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/plugins/sqldrivers/odbc/qsql_odbc.cpp b/src/plugins/sqldrivers/odbc/qsql_odbc.cpp index bcd8a72e28..1a57e8fcc6 100644 --- a/src/plugins/sqldrivers/odbc/qsql_odbc.cpp +++ b/src/plugins/sqldrivers/odbc/qsql_odbc.cpp @@ -80,7 +80,6 @@ inline static QVarLengthArray<SQLTCHAR> toSQLTCHAR(const QString &input) result.resize(enc.requiredSpace(input.size())); const auto end = enc.appendToBuffer(reinterpret_cast<char *>(result.data()), input); result.resize((end - reinterpret_cast<char *>(result.data())) / sizeof(SQLTCHAR)); - result.append(0); // make sure it's null terminated, doesn't matter if it already is, it does if it isn't. return result; } @@ -2058,7 +2057,8 @@ void QODBCDriverPrivate::checkUnicode() "select 'test' from dual"_L1, }; for (const auto &statement : statements) { - r = SQLExecDirect(hStmt, toSQLTCHAR(statement).data(), SQL_NTS); + auto encoded = toSQLTCHAR(statement); + r = SQLExecDirect(hStmt, encoded.data(), SQLINTEGER(encoded.size())); if (r == SQL_SUCCESS) break; } |