-
Notifications
You must be signed in to change notification settings - Fork 19
Add ASAN and Valgrind integration for CI test suite #289
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
Changes from 16 commits
65df21f
1b21cf2
2e5af48
832d8e7
8ea653f
84b9dec
e28f255
52f0495
b7aa955
5323214
836e6d4
f20e6fc
9daab27
8258a27
0f8f90f
bea6403
09b934a
98115a1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,21 @@ | |
| extern FILE *logFile; | ||
| using namespace OdbcJdbcLibrary; | ||
|
|
||
| #ifndef _WINDOWS | ||
| // SQLWCHAR-aware length (in SQLWCHAR units), safe on Linux where | ||
| // sizeof(wchar_t) != sizeof(SQLWCHAR). Do NOT use wcslen() on SQLWCHAR | ||
| // data on Linux — it reads two SQLWCHARs per wchar_t and runs off the end. | ||
| static size_t sqlwcharLen( const SQLWCHAR *s ) | ||
| { | ||
| size_t n = 0; | ||
| if ( !s ) | ||
| return 0; | ||
| while ( s[n] ) | ||
| ++n; | ||
| return n; | ||
| } | ||
| #endif | ||
|
|
||
| #ifdef _WINDOWS | ||
| extern UINT codePage; // from Main.cpp | ||
| #endif | ||
|
|
@@ -85,7 +100,7 @@ class ConvertingString | |
| if ( length == SQL_NTS ) | ||
| lengthString = 0; | ||
| else if ( retCountOfBytes ) | ||
| lengthString = length / sizeof(wchar_t); | ||
| lengthString = length / sizeof(SQLWCHAR); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And please! Have you forgotten that this change causes a stack smash?)) Simply because the the lengthString becomes greater, and the This undoubtedly right change CAN NOT be done without a deep refactoring of the unicode routins. I thought I've explaned it clearly in #289 (comment)
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You were right — this change alone breaks the symmetric
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right. But it's insufficient to close this thread, please revert the changes) return the line 88 back to the original
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Cannot see where the line 88 is reverted in ^^^ |
||
| else | ||
| lengthString = length; | ||
| } | ||
|
|
@@ -135,13 +150,33 @@ class ConvertingString | |
| if ( len > 0 ) | ||
| len--; | ||
| #else | ||
| len = mbstowcs( (wchar_t*)unicodeString, (const char*)byteString, lengthString ); | ||
| // SQLWCHAR is 2 bytes on Linux (unixODBC defines it as unsigned short), | ||
| // but wchar_t is 4 bytes, so mbstowcs((wchar_t*)unicodeString, ...) | ||
| // both corrupts the output and risks overflowing the caller's buffer. | ||
| // Widen byte-by-byte into SQLWCHAR units, matching what unixODBC's | ||
| // ansi_to_unicode_copy() does internally. This is correct for the | ||
| // ASCII-only error/state strings that reach this code path; non-ASCII | ||
| // input will be handled by the broader ConvertingString rewrite tracked | ||
| // in issue #287 (Tier 9.1). | ||
| { | ||
| const SQLCHAR *src = byteString; | ||
| size_t i = 0; | ||
| while ( i < (size_t)lengthString && src[i] != 0 ) | ||
| { | ||
| unicodeString[i] = (SQLWCHAR)( src[i] & 0xFF ); | ||
| ++i; | ||
| } | ||
| len = i; | ||
| } | ||
| #endif | ||
| } | ||
|
|
||
| if ( len > 0 ) | ||
| { | ||
| *(LPWSTR)(unicodeString + len) = L'\0'; | ||
| // NUL-terminate in SQLWCHAR units. LPWSTR assignment of L'\0' writes | ||
|
fdcastel marked this conversation as resolved.
Outdated
|
||
| // sizeof(wchar_t) bytes, which overruns the output buffer by 2 bytes | ||
| // on Linux. | ||
| unicodeString[len] = 0; | ||
|
|
||
| if ( realLength ) | ||
| { | ||
|
|
@@ -170,12 +205,18 @@ class ConvertingString | |
| wchar_t saveWC; | ||
|
|
||
| if ( length == SQL_NTS ) | ||
| #ifdef _WINDOWS | ||
| length = (int)wcslen( (const wchar_t*)wcString ); | ||
| else if ( wcString[length] != L'\0' ) | ||
| #else | ||
| length = (int)sqlwcharLen( wcString ); | ||
| #endif | ||
| else if ( wcString[length] != 0 ) | ||
| { | ||
| ptEndWC = (wchar_t*)&wcString[length]; | ||
| saveWC = *ptEndWC; | ||
| *ptEndWC = L'\0'; | ||
| // Write a SQLWCHAR-sized NUL so we don't overrun the input by 2 bytes | ||
| // on Linux (wchar_t is 4 bytes there). | ||
| wcString[length] = 0; | ||
| } | ||
|
|
||
| if ( connection ) | ||
|
|
@@ -185,7 +226,10 @@ class ConvertingString | |
| #ifdef _WINDOWS | ||
| bytesNeeded = WideCharToMultiByte( codePage, (DWORD)0, wcString, length, NULL, (int)0, NULL, NULL ); | ||
| #else | ||
| bytesNeeded = wcstombs( NULL, (const wchar_t*)wcString, length ); | ||
| // See the symmetric comment in the destructor above: wcstombs assumes | ||
| // wchar_t-sized input, which corrupts SQLWCHAR data on Linux. The | ||
| // byte-narrowing loop below produces exactly `length` output bytes. | ||
| bytesNeeded = (size_t)length; | ||
| #endif | ||
| } | ||
|
|
||
|
|
@@ -198,7 +242,15 @@ class ConvertingString | |
| #ifdef _WINDOWS | ||
| bytesNeeded = WideCharToMultiByte( codePage, 0, wcString, length, (LPSTR)byteString, (int)bytesNeeded, NULL, NULL ); | ||
| #else | ||
| bytesNeeded = wcstombs( (char *)byteString, (const wchar_t*)wcString, bytesNeeded ); | ||
| { | ||
| size_t i = 0; | ||
| while ( i < (size_t)length && wcString[i] != 0 ) | ||
| { | ||
| byteString[i] = (SQLCHAR)( wcString[i] & 0xFF ); | ||
| ++i; | ||
| } | ||
| bytesNeeded = i; | ||
| } | ||
| #endif | ||
| } | ||
|
|
||
|
|
@@ -220,7 +272,7 @@ class ConvertingString | |
| if ( lengthString ) | ||
| { | ||
| byteString = new SQLCHAR[ lengthString + 2 ]; | ||
| memset(byteString, 0, lengthString + 2); | ||
| memset( byteString, 0, lengthString + 2 ); | ||
| } | ||
| else | ||
| byteString = NULL; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.