[PATCH] msvcrt: Don't crash if _vsnwprintf gets NULL as format string

Fabian Maurer dark.shadow4 at web.de
Sun Oct 1 16:18:30 CDT 2017


Signed-off-by: Fabian Maurer <dark.shadow4 at web.de>
---
 dlls/msvcrt/printf.h       | 3 +++
 dlls/msvcrt/tests/printf.c | 6 ++++++
 2 files changed, 9 insertions(+)

diff --git a/dlls/msvcrt/printf.h b/dlls/msvcrt/printf.h
index fe1e127c76..5e4fbc8869 100644
--- a/dlls/msvcrt/printf.h
+++ b/dlls/msvcrt/printf.h
@@ -376,6 +376,9 @@ int FUNC_NAME(pf_printf)(FUNC_NAME(puts_clbk) pf_puts, void *puts_ctx, const API
 
     TRACE("Format is: %s\n", FUNC_NAME(debugstr)(fmt));
 
+    if(!fmt)
+        return -1;
+
     if(!locale)
         locinfo = get_locinfo();
     else
diff --git a/dlls/msvcrt/tests/printf.c b/dlls/msvcrt/tests/printf.c
index f9b3fc9ff0..6caed8fbaa 100644
--- a/dlls/msvcrt/tests/printf.c
+++ b/dlls/msvcrt/tests/printf.c
@@ -1226,6 +1226,12 @@ static void test_vsnwprintf(void)
 
     ret = _vsnwprintf_wrapper( NULL, 0, format, one, two, three );
     ok( ret == 11 || broken(ret == -1 /* Win2k */), "got %d, expected 11\n", ret );
+
+    /* Test with format string set to NULL, we should not crash */
+    str[0] = 'x';
+    ret = _vsnwprintf_wrapper( str, 0, NULL );
+    ok( ret == -1, "got %d, expected -1\n", ret );
+    ok( str[0] == 'x', "Expected string to be unchanged.\n" );
 }
 
 static int __cdecl vswprintf_wrapper(wchar_t *str, const wchar_t *format, ...)
-- 
2.14.2




More information about the wine-patches mailing list