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

Signed-off-by: Dmitry Timoshkov <dmitry@baikal.ru>
Signed-off-by: Sebastian Lackner <sebastian@fds-team.de>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Dmitry Timoshkov 2016-07-08 05:12:11 +02:00 committed by Alexandre Julliard
parent 80d655ca75
commit 59ba31d1fc
2 changed files with 40 additions and 1 deletions

View File

@ -166,7 +166,7 @@ BOOL WINAPI CharToOemBuffA( LPCSTR s, LPSTR d, DWORD len )
*/ */
BOOL WINAPI CharToOemBuffW( LPCWSTR 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 ); WideCharToMultiByte( CP_OEMCP, 0, s, len, d, len, NULL, NULL );
return TRUE; return TRUE;
} }
@ -177,6 +177,7 @@ BOOL WINAPI CharToOemBuffW( LPCWSTR s, LPSTR d, DWORD len )
*/ */
BOOL WINAPI CharToOemW( LPCWSTR s, LPSTR d ) BOOL WINAPI CharToOemW( LPCWSTR s, LPSTR d )
{ {
if (!s || !d) return FALSE;
return CharToOemBuffW( s, d, lstrlenW( s ) + 1 ); 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 ) BOOL WINAPI OemToCharBuffW( LPCSTR s, LPWSTR d, DWORD len )
{ {
if (!s || !d) return FALSE;
MultiByteToWideChar( CP_OEMCP, 0, s, len, d, len ); MultiByteToWideChar( CP_OEMCP, 0, s, len, d, len );
return TRUE; return TRUE;
} }
@ -226,6 +228,7 @@ BOOL WINAPI OemToCharBuffW( LPCSTR s, LPWSTR d, DWORD len )
*/ */
BOOL WINAPI OemToCharW( LPCSTR s, LPWSTR d ) BOOL WINAPI OemToCharW( LPCSTR s, LPWSTR d )
{ {
if (!s || !d) return FALSE;
return OemToCharBuffW( s, d, strlen( s ) + 1 ); return OemToCharBuffW( s, d, strlen( s ) + 1 );
} }

View File

@ -730,6 +730,8 @@ static void test_DrawState(void)
static void test_CharToOem_OemToChar(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 char helloWorld[] = "Hello World";
static const struct 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(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); 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) START_TEST(text)