diff --git a/sdk/include/reactos/wine/test.h b/sdk/include/reactos/wine/test.h index 8b9035adfcf..db723249c5e 100644 --- a/sdk/include/reactos/wine/test.h +++ b/sdk/include/reactos/wine/test.h @@ -26,6 +26,11 @@ #include #include +#ifndef _STRSAFE_H_INCLUDED_ +#include +#include +#endif + #ifdef __WINE_CONFIG_H #error config.h should not be used in Wine tests #endif @@ -638,14 +643,17 @@ const char *wine_dbgstr_wn( const WCHAR *str, intptr_t n ) { char *dst, *res; size_t size; + size_t CbLength = 0; + HRESULT hr; + 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 (IsBadStringPtrW(str,n)) return "(invalid)"; if (n == -1) { const WCHAR *end = str; @@ -655,6 +663,17 @@ const char *wine_dbgstr_wn( const WCHAR *str, intptr_t n ) if (n < 0) n = 0; size = 12 + min( 300, n * 5 ); dst = res = get_temp_buffer( size ); + + hr = StringCbLengthW((STRSAFE_LPCWSTR)str, size, &CbLength); + if (SUCCEEDED(hr)) + { + n = min(n, CbLength/2); + } + else + { + return "(invalid)"; + } + *dst++ = 'L'; *dst++ = '"'; while (n-- > 0 && dst <= res + size - 10)