[ROSTESTS] Fix crash in winhttp:winhttp test (#4303)

Fix regression crash in wine_dbgstr_wn. ROSTESTS-377

This brings most of Wine's current wine_dbgstr_wn code into ReactOS.
It's not possible to completely sync this with latest Wine because
there is Wine-specific code regarding "debug_info" and their TEB
in remaining code. Confirmed by @ThFabba.
This commit is contained in:
Doug Lyons 2022-04-29 13:50:54 -05:00 committed by GitHub
parent 57d7f6f6b3
commit dbc7eeb47e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -698,28 +698,22 @@ const char *wine_dbgstr_an( const CHAR *str, intptr_t n )
const char *wine_dbgstr_wn( const WCHAR *str, intptr_t n ) const char *wine_dbgstr_wn( const WCHAR *str, intptr_t n )
{ {
char *dst, *res; char *res;
size_t size; static const char hex[16] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
char buffer[300], *dst = buffer;
if (!str) return "(null)";
if (!((ULONG_PTR)str >> 16)) if (!((ULONG_PTR)str >> 16))
{ {
if (!str) return "(null)";
res = get_temp_buffer( 6 ); res = get_temp_buffer( 6 );
sprintf( res, "#%04x", LOWORD(str) ); sprintf( res, "#%04x", LOWORD(str) );
return res; return res;
} }
if (n == -1) if (IsBadStringPtrW(str,n)) return "(invalid)";
{ if (n == -1) for (n = 0; str[n]; n++) ;
const WCHAR *end = str;
while (*end) end++;
n = end - str;
}
if (n < 0) n = 0;
size = 12 + min( 300, n * 5 );
dst = res = get_temp_buffer( size );
*dst++ = 'L'; *dst++ = 'L';
*dst++ = '"'; *dst++ = '"';
while (n-- > 0 && dst <= res + size - 10) while (n-- > 0 && dst <= buffer + sizeof(buffer) - 10)
{ {
WCHAR c = *str++; WCHAR c = *str++;
switch (c) switch (c)
@ -730,14 +724,15 @@ const char *wine_dbgstr_wn( const WCHAR *str, intptr_t n )
case '"': *dst++ = '\\'; *dst++ = '"'; break; case '"': *dst++ = '\\'; *dst++ = '"'; break;
case '\\': *dst++ = '\\'; *dst++ = '\\'; break; case '\\': *dst++ = '\\'; *dst++ = '\\'; break;
default: default:
if (c >= ' ' && c <= 126) if (c < ' ' || c >= 127)
*dst++ = (char)c;
else
{ {
*dst++ = '\\'; *dst++ = '\\';
sprintf(dst,"%04x",c); *dst++ = hex[(c >> 12) & 0x0f];
dst+=4; *dst++ = hex[(c >> 8) & 0x0f];
*dst++ = hex[(c >> 4) & 0x0f];
*dst++ = hex[c & 0x0f];
} }
else *dst++ = (char)c;
} }
} }
*dst++ = '"'; *dst++ = '"';
@ -747,8 +742,10 @@ const char *wine_dbgstr_wn( const WCHAR *str, intptr_t n )
*dst++ = '.'; *dst++ = '.';
*dst++ = '.'; *dst++ = '.';
} }
*dst++ = 0; *dst = 0;
release_temp_buffer( res, dst - res );
res = get_temp_buffer(strlen(buffer + 1));
strcpy(res, buffer);
return res; return res;
} }