https://git.reactos.org/?p=reactos.git;a=commitdiff;h=dbc7eeb47e5527bdad0cf…
commit dbc7eeb47e5527bdad0cf3366a2f6644544ae423
Author: Doug Lyons <douglyons(a)douglyons.com>
AuthorDate: Fri Apr 29 13:50:54 2022 -0500
Commit: GitHub <noreply(a)github.com>
CommitDate: Fri Apr 29 21:50:54 2022 +0300
[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.
---
sdk/include/reactos/wine/test.h | 37 +++++++++++++++++--------------------
1 file changed, 17 insertions(+), 20 deletions(-)
diff --git a/sdk/include/reactos/wine/test.h b/sdk/include/reactos/wine/test.h
index 414215ab0c4..0cbc40010b5 100644
--- a/sdk/include/reactos/wine/test.h
+++ b/sdk/include/reactos/wine/test.h
@@ -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 )
{
- char *dst, *res;
- size_t size;
+ char *res;
+ 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 (!str) return "(null)";
res = get_temp_buffer( 6 );
sprintf( res, "#%04x", LOWORD(str) );
return res;
}
- if (n == -1)
- {
- 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 );
+ if (IsBadStringPtrW(str,n)) return "(invalid)";
+ if (n == -1) for (n = 0; str[n]; n++) ;
*dst++ = 'L';
*dst++ = '"';
- while (n-- > 0 && dst <= res + size - 10)
+ while (n-- > 0 && dst <= buffer + sizeof(buffer) - 10)
{
WCHAR c = *str++;
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;
default:
- if (c >= ' ' && c <= 126)
- *dst++ = (char)c;
- else
+ if (c < ' ' || c >= 127)
{
*dst++ = '\\';
- sprintf(dst,"%04x",c);
- dst+=4;
+ *dst++ = hex[(c >> 12) & 0x0f];
+ *dst++ = hex[(c >> 8) & 0x0f];
+ *dst++ = hex[(c >> 4) & 0x0f];
+ *dst++ = hex[c & 0x0f];
}
+ else *dst++ = (char)c;
}
}
*dst++ = '"';
@@ -747,8 +742,10 @@ const char *wine_dbgstr_wn( const WCHAR *str, intptr_t n )
*dst++ = '.';
*dst++ = '.';
}
- *dst++ = 0;
- release_temp_buffer( res, dst - res );
+ *dst = 0;
+
+ res = get_temp_buffer(strlen(buffer + 1));
+ strcpy(res, buffer);
return res;
}