[PATCH 1/3] ntdll/tests: Test if RtlFormatMessage modifies va_list on error.

Daniel Lehman wine at gitlab.winehq.org
Sat Jun 4 11:28:02 CDT 2022


From: Daniel Lehman <dlehman25 at gmail.com>

Signed-off-by: Daniel Lehman <dlehman25 at gmail.com>
---
 dlls/ntdll/tests/rtlstr.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/dlls/ntdll/tests/rtlstr.c b/dlls/ntdll/tests/rtlstr.c
index 1bce812ff13..5ffa16f8e16 100644
--- a/dlls/ntdll/tests/rtlstr.c
+++ b/dlls/ntdll/tests/rtlstr.c
@@ -2641,6 +2641,25 @@ static void WINAPIV testfmt( const WCHAR *src, const WCHAR *expect, ULONG width,
     ok( size == (lstrlenW(expect) + 1) * sizeof(WCHAR), "%s: wrong size %lu\n", debugstr_w(src), size );
 }
 
+static void testfmt_arg_eaten( const WCHAR *src, ... )
+{
+    va_list args;
+    NTSTATUS status;
+    WCHAR *arg, buffer[1];
+    ULONG size = 0xdeadbeef;
+
+    buffer[0] = 0xcccc;
+    va_start( args, src );
+    status = pRtlFormatMessage( src, 0, FALSE, FALSE, FALSE, &args, buffer, ARRAY_SIZE(buffer), &size );
+    ok( status == STATUS_BUFFER_OVERFLOW, "%s: failed %lx\n", debugstr_w(src), status );
+    todo_wine
+    ok( buffer[0] == 0xcccc, "%s: got %x\n", debugstr_w(src), buffer[0] );
+    ok( size == 0xdeadbeef, "%s: wrong size %lu\n", debugstr_w(src), size );
+    arg = va_arg( args, WCHAR * );
+    ok( !wcscmp( L"unused", arg ), "%s: wrong arg %s\n", debugstr_w(src), debugstr_w(arg) );
+    va_end( args );
+}
+
 static void test_RtlFormatMessage(void)
 {
     WCHAR buffer[128];
@@ -2888,6 +2907,8 @@ static void test_RtlFormatMessage(void)
     ok( !lstrcmpW( buffer, L"abcxxxxxxx" ), "got %s\n", wine_dbgstr_w(buffer) );
     ok( size == 0xdeadbeef, "wrong size %lu\n", size );
 
+    /* va_arg is eaten even in case of buffer overflow */
+    testfmt_arg_eaten( L"%1!s! %2!s!", L"eaten", L"unused" );
 }
 
 START_TEST(rtlstr)
-- 
GitLab


https://gitlab.winehq.org/wine/wine/-/merge_requests/187



More information about the wine-devel mailing list