kernel32: Don't crash accessing an invalid handle in GlobalSize.

oldstable
James Hawkins 2007-09-20 01:49:26 -05:00 committed by Alexandre Julliard
parent b095ade908
commit 8e90c6099e
2 changed files with 12 additions and 1 deletions

View File

@ -807,7 +807,11 @@ SIZE_T WINAPI GlobalSize(HGLOBAL hmem)
DWORD retval;
PGLOBAL32_INTERN pintern;
if (!hmem) return 0;
if (!((ULONG_PTR)hmem >> 16))
{
SetLastError(ERROR_INVALID_HANDLE);
return 0;
}
if(ISPOINTER(hmem))
{

View File

@ -197,6 +197,13 @@ START_TEST(heap)
res = GlobalUnlock(gbl);
ok(res == 1, "Expected 1, got %d\n", res);
/* GlobalSize on an invalid handle */
SetLastError(MAGIC_DEAD);
size = GlobalSize((HGLOBAL)0xc042);
ok(size == 0, "Expected 0, got %ld\n", size);
ok(GetLastError() == ERROR_INVALID_HANDLE,
"Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
/* ####################################### */
/* Local*() functions */
gbl = LocalAlloc(LMEM_MOVEABLE, 0);