kernel32: Improve parameter validation for WriteConsoleOutputAttribute.

This commit is contained in:
Andrew Nguyen 2011-01-03 21:25:34 -06:00 committed by Alexandre Julliard
parent 5f70cd6509
commit 8ec12b5110
2 changed files with 93 additions and 3 deletions

View File

@ -694,6 +694,14 @@ BOOL WINAPI WriteConsoleOutputAttribute( HANDLE hConsoleOutput, CONST WORD *attr
TRACE("(%p,%p,%d,%dx%d,%p)\n", hConsoleOutput,attr,length,coord.X,coord.Y,lpNumAttrsWritten); TRACE("(%p,%p,%d,%dx%d,%p)\n", hConsoleOutput,attr,length,coord.X,coord.Y,lpNumAttrsWritten);
if ((length > 0 && !attr) || !lpNumAttrsWritten)
{
SetLastError(ERROR_INVALID_ACCESS);
return FALSE;
}
*lpNumAttrsWritten = 0;
SERVER_START_REQ( write_console_output ) SERVER_START_REQ( write_console_output )
{ {
req->handle = console_handle_unmap(hConsoleOutput); req->handle = console_handle_unmap(hConsoleOutput);
@ -703,9 +711,7 @@ BOOL WINAPI WriteConsoleOutputAttribute( HANDLE hConsoleOutput, CONST WORD *attr
req->wrap = TRUE; req->wrap = TRUE;
wine_server_add_data( req, attr, length * sizeof(WORD) ); wine_server_add_data( req, attr, length * sizeof(WORD) );
if ((ret = !wine_server_call_err( req ))) if ((ret = !wine_server_call_err( req )))
{ *lpNumAttrsWritten = reply->written;
if (lpNumAttrsWritten) *lpNumAttrsWritten = reply->written;
}
} }
SERVER_END_REQ; SERVER_END_REQ;
return ret; return ret;

View File

@ -1569,6 +1569,89 @@ static void test_WriteConsoleOutputCharacterW(HANDLE output_handle)
ok(count == 1, "Expected count to be 1, got %u\n", count); ok(count == 1, "Expected count to be 1, got %u\n", count);
} }
static void test_WriteConsoleOutputAttribute(HANDLE output_handle)
{
WORD attr = FOREGROUND_BLUE;
COORD origin = {0, 0};
DWORD count;
BOOL ret;
int i;
const struct
{
HANDLE hConsoleOutput;
CONST WORD *attr;
DWORD length;
COORD coord;
LPDWORD lpNumAttrsWritten;
DWORD expected_count;
DWORD last_error;
int win7_crash;
} invalid_table[] =
{
{NULL, NULL, 0, origin, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
{NULL, NULL, 0, origin, &count, 0, ERROR_INVALID_HANDLE},
{NULL, NULL, 1, origin, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
{NULL, NULL, 1, origin, &count, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
{NULL, &attr, 0, origin, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
{NULL, &attr, 0, origin, &count, 0, ERROR_INVALID_HANDLE},
{NULL, &attr, 1, origin, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
{NULL, &attr, 1, origin, &count, 0, ERROR_INVALID_HANDLE},
{INVALID_HANDLE_VALUE, NULL, 0, origin, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
{INVALID_HANDLE_VALUE, NULL, 0, origin, &count, 0, ERROR_INVALID_HANDLE},
{INVALID_HANDLE_VALUE, NULL, 1, origin, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
{INVALID_HANDLE_VALUE, NULL, 1, origin, &count, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
{INVALID_HANDLE_VALUE, &attr, 0, origin, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
{INVALID_HANDLE_VALUE, &attr, 0, origin, &count, 0, ERROR_INVALID_HANDLE},
{INVALID_HANDLE_VALUE, &attr, 1, origin, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
{INVALID_HANDLE_VALUE, &attr, 1, origin, &count, 0, ERROR_INVALID_HANDLE},
{output_handle, NULL, 0, origin, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
{output_handle, NULL, 1, origin, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
{output_handle, NULL, 1, origin, &count, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
{output_handle, &attr, 0, origin, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
{output_handle, &attr, 1, origin, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
};
for (i = 0; i < sizeof(invalid_table)/sizeof(invalid_table[0]); i++)
{
if (invalid_table[i].win7_crash)
continue;
SetLastError(0xdeadbeef);
if (invalid_table[i].lpNumAttrsWritten) count = 0xdeadbeef;
ret = WriteConsoleOutputAttribute(invalid_table[i].hConsoleOutput,
invalid_table[i].attr,
invalid_table[i].length,
invalid_table[i].coord,
invalid_table[i].lpNumAttrsWritten);
ok(!ret, "[%d] Expected WriteConsoleOutputAttribute to return FALSE, got %d\n", i, ret);
if (invalid_table[i].lpNumAttrsWritten)
{
ok(count == invalid_table[i].expected_count,
"[%d] Expected count to be %u, got %u\n",
i, invalid_table[i].expected_count, count);
}
ok(GetLastError() == invalid_table[i].last_error,
"[%d] Expected last error to be %u, got %u\n",
i, invalid_table[i].last_error, GetLastError());
}
count = 0xdeadbeef;
ret = WriteConsoleOutputAttribute(output_handle, NULL, 0, origin, &count);
ok(ret == TRUE, "Expected WriteConsoleOutputAttribute to return TRUE, got %d\n", ret);
ok(count == 0, "Expected count to be 0, got %u\n", count);
count = 0xdeadbeef;
ret = WriteConsoleOutputAttribute(output_handle, &attr, 0, origin, &count);
ok(ret == TRUE, "Expected WriteConsoleOutputAttribute to return TRUE, got %d\n", ret);
ok(count == 0, "Expected count to be 0, got %u\n", count);
count = 0xdeadbeef;
ret = WriteConsoleOutputAttribute(output_handle, &attr, 1, origin, &count);
ok(ret == TRUE, "Expected WriteConsoleOutputAttribute to return TRUE, got %d\n", ret);
ok(count == 1, "Expected count to be 1, got %u\n", count);
}
START_TEST(console) START_TEST(console)
{ {
HANDLE hConIn, hConOut; HANDLE hConIn, hConOut;
@ -1627,4 +1710,5 @@ START_TEST(console)
test_WriteConsoleInputW(hConIn); test_WriteConsoleInputW(hConIn);
test_WriteConsoleOutputCharacterA(hConOut); test_WriteConsoleOutputCharacterA(hConOut);
test_WriteConsoleOutputCharacterW(hConOut); test_WriteConsoleOutputCharacterW(hConOut);
test_WriteConsoleOutputAttribute(hConOut);
} }