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

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:11:42 +02:00 committed by Alexandre Julliard
parent 827f97c1ab
commit 80d655ca75
2 changed files with 53 additions and 2 deletions

View File

@ -136,7 +136,7 @@ LPWSTR WINAPI CharPrevW(LPCWSTR start,LPCWSTR x)
*/
BOOL WINAPI CharToOemA( LPCSTR s, LPSTR d )
{
if ( !s || !d ) return TRUE;
if (!s || !d) return FALSE;
return CharToOemBuffA( s, d, strlen( s ) + 1 );
}
@ -148,6 +148,8 @@ BOOL WINAPI CharToOemBuffA( LPCSTR s, LPSTR d, DWORD len )
{
WCHAR *bufW;
if (!s || !d) return FALSE;
bufW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
if( bufW )
{
@ -184,6 +186,7 @@ BOOL WINAPI CharToOemW( LPCWSTR s, LPSTR d )
*/
BOOL WINAPI OemToCharA( LPCSTR s, LPSTR d )
{
if (!s || !d) return FALSE;
return OemToCharBuffA( s, d, strlen( s ) + 1 );
}
@ -195,6 +198,8 @@ BOOL WINAPI OemToCharBuffA( LPCSTR s, LPSTR d, DWORD len )
{
WCHAR *bufW;
if (!s || !d) return FALSE;
bufW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
if( bufW )
{

View File

@ -2,7 +2,7 @@
* DrawText tests
*
* Copyright (c) 2004 Zach Gorman
* Copyright 2007 Dmitry Timoshkov
* Copyright 2007,2016 Dmitry Timoshkov
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -728,9 +728,55 @@ static void test_DrawState(void)
DestroyWindow(hwnd);
}
static void test_CharToOem_OemToChar(void)
{
static const char helloWorld[] = "Hello World";
static const struct
{
BOOL src, dst, ret;
}
tests[] =
{
{ FALSE, FALSE, FALSE },
{ TRUE, FALSE, FALSE },
{ FALSE, TRUE, FALSE },
{ TRUE, TRUE, TRUE },
};
BOOL ret;
int i;
for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++)
{
const char *expected = tests[i].ret ? helloWorld : "";
const char *src = tests[i].src ? helloWorld : NULL;
char buf[64], *dst = tests[i].dst ? buf : NULL;
memset(buf, 0, sizeof(buf));
ret = CharToOemA(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 = CharToOemBuffA(src, dst, sizeof(helloWorld));
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 = OemToCharA(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 = OemToCharBuffA(src, dst, sizeof(helloWorld));
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);
}
}
START_TEST(text)
{
test_TabbedText();
test_DrawTextCalcRect();
test_DrawState();
test_CharToOem_OemToChar();
}