Dmitry Timoshkov : user32: Properly handle invalid parameters in CharToOem [Buff]W and OemToChar[Buff]W.

Alexandre Julliard julliard at winehq.org
Fri Jul 8 10:02:04 CDT 2016


Module: wine
Branch: master
Commit: 59ba31d1fc36d04f6e69db6533411a1c120329d0
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=59ba31d1fc36d04f6e69db6533411a1c120329d0

Author: Dmitry Timoshkov <dmitry at baikal.ru>
Date:   Fri Jul  8 05:12:11 2016 +0200

user32: Properly handle invalid parameters in CharToOem[Buff]W and OemToChar[Buff]W.

Signed-off-by: Dmitry Timoshkov <dmitry at baikal.ru>
Signed-off-by: Sebastian Lackner <sebastian at fds-team.de>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/user32/lstr.c       |  5 ++++-
 dlls/user32/tests/text.c | 36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/dlls/user32/lstr.c b/dlls/user32/lstr.c
index 79a7b27..42e55c0 100644
--- a/dlls/user32/lstr.c
+++ b/dlls/user32/lstr.c
@@ -166,7 +166,7 @@ BOOL WINAPI CharToOemBuffA( LPCSTR s, LPSTR d, DWORD len )
  */
 BOOL WINAPI CharToOemBuffW( LPCWSTR s, LPSTR d, DWORD len )
 {
-    if ( !s || !d ) return TRUE;
+    if (!s || !d) return FALSE;
     WideCharToMultiByte( CP_OEMCP, 0, s, len, d, len, NULL, NULL );
     return TRUE;
 }
@@ -177,6 +177,7 @@ BOOL WINAPI CharToOemBuffW( LPCWSTR s, LPSTR d, DWORD len )
  */
 BOOL WINAPI CharToOemW( LPCWSTR s, LPSTR d )
 {
+    if (!s || !d) return FALSE;
     return CharToOemBuffW( s, d, lstrlenW( s ) + 1 );
 }
 
@@ -216,6 +217,7 @@ BOOL WINAPI OemToCharBuffA( LPCSTR s, LPSTR d, DWORD len )
  */
 BOOL WINAPI OemToCharBuffW( LPCSTR s, LPWSTR d, DWORD len )
 {
+    if (!s || !d) return FALSE;
     MultiByteToWideChar( CP_OEMCP, 0, s, len, d, len );
     return TRUE;
 }
@@ -226,6 +228,7 @@ BOOL WINAPI OemToCharBuffW( LPCSTR s, LPWSTR d, DWORD len )
  */
 BOOL WINAPI OemToCharW( LPCSTR s, LPWSTR d )
 {
+    if (!s || !d) return FALSE;
     return OemToCharBuffW( s, d, strlen( s ) + 1 );
 }
 
diff --git a/dlls/user32/tests/text.c b/dlls/user32/tests/text.c
index 172ab6e..bebf6a0 100644
--- a/dlls/user32/tests/text.c
+++ b/dlls/user32/tests/text.c
@@ -730,6 +730,8 @@ static void test_DrawState(void)
 
 static void test_CharToOem_OemToChar(void)
 {
+    static const WCHAR helloWorldW[] = {'H','e','l','l','o',' ','W','o','r','l','d',0};
+    static const WCHAR emptyW[] = {0};
     static const char helloWorld[] = "Hello World";
     static const struct
     {
@@ -771,6 +773,40 @@ static void test_CharToOem_OemToChar(void)
         ok(ret == tests[i].ret, "test %d: expected %d, got %d\n", i, tests[i].ret, ret);
         ok(!strcmp(buf, expected), "test %d: got '%s'\n", i, buf);
     }
+
+    for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++)
+    {
+        const char *expected = tests[i].ret ? helloWorld : "";
+        const WCHAR *src = tests[i].src ? helloWorldW : NULL;
+        char buf[64], *dst = tests[i].dst ? buf : NULL;
+
+        memset(buf, 0, sizeof(buf));
+        ret = CharToOemW(src, dst);
+        ok(ret == tests[i].ret, "test %d: expected %d, got %d\n", i, tests[i].ret, ret);
+        ok(!strcmp(buf, expected), "test %d: got '%s'\n", i, buf);
+
+        memset(buf, 0, sizeof(buf));
+        ret = CharToOemBuffW(src, dst, sizeof(helloWorldW)/sizeof(WCHAR));
+        ok(ret == tests[i].ret, "test %d: expected %d, got %d\n", i, tests[i].ret, ret);
+        ok(!strcmp(buf, expected), "test %d: got '%s'\n", i, buf);
+    }
+
+    for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++)
+    {
+        const WCHAR *expected = tests[i].ret ? helloWorldW : emptyW;
+        const char *src = tests[i].src ? helloWorld : NULL;
+        WCHAR buf[64], *dst = tests[i].dst ? buf : NULL;
+
+        memset(buf, 0, sizeof(buf));
+        ret = OemToCharW(src, dst);
+        ok(ret == tests[i].ret, "test %d: expected %d, got %d\n", i, tests[i].ret, ret);
+        ok(!lstrcmpW(buf, expected), "test %d: got '%s'\n", i, wine_dbgstr_w(buf));
+
+        memset(buf, 0, sizeof(buf));
+        ret = OemToCharBuffW(src, dst, sizeof(helloWorld));
+        ok(ret == tests[i].ret, "test %d: expected %d, got %d\n", i, tests[i].ret, ret);
+        ok(!lstrcmpW(buf, expected), "test %d: got '%s'\n", i, wine_dbgstr_w(buf));
+    }
 }
 
 START_TEST(text)




More information about the wine-cvs mailing list