kernel: Fix handling of invalid parameter in GlobalFlags().

This commit is contained in:
Detlef Riekenberg 2006-03-29 20:48:39 +02:00 committed by Alexandre Julliard
parent 5ca18a1135
commit 1a81f4ff8a
2 changed files with 24 additions and 10 deletions

View File

@ -837,16 +837,16 @@ VOID WINAPI GlobalUnfix(HGLOBAL hmem)
* *
* Get information about a global memory object. * Get information about a global memory object.
* *
* NOTES * PARAMS
* Should this return GMEM_INVALID_HANDLE on invalid handle? * hmem [I] Handle of the global memory object
* *
* RETURNS * RETURNS
* Value specifying allocation flags and lock count * Failure: GMEM_INVALID_HANDLE, when the provided handle is invalid
* GMEM_INVALID_HANDLE: Failure * Success: Value specifying allocation flags and lock count
*
*/ */
UINT WINAPI GlobalFlags( UINT WINAPI GlobalFlags(HGLOBAL hmem)
HGLOBAL hmem /* [in] Handle to global memory object */ {
) {
DWORD retval; DWORD retval;
PGLOBAL32_INTERN pintern; PGLOBAL32_INTERN pintern;
@ -866,8 +866,9 @@ UINT WINAPI GlobalFlags(
} }
else else
{ {
WARN("Invalid handle: %p\n", hmem); WARN("invalid handle %p (Magic: 0x%04x)\n", hmem, pintern->Magic);
retval=0; SetLastError(ERROR_INVALID_HANDLE);
retval = GMEM_INVALID_HANDLE;
} }
RtlUnlockHeap(GetProcessHeap()); RtlUnlockHeap(GetProcessHeap());
} }

View File

@ -36,6 +36,7 @@ static SIZE_T resize_9x(SIZE_T size)
START_TEST(heap) START_TEST(heap)
{ {
void *mem; void *mem;
UINT flags;
HGLOBAL gbl; HGLOBAL gbl;
HGLOBAL hsecond; HGLOBAL hsecond;
SIZE_T size; SIZE_T size;
@ -86,6 +87,12 @@ START_TEST(heap)
ok( (hsecond == gbl) && (GetLastError() == ERROR_INVALID_HANDLE), ok( (hsecond == gbl) && (GetLastError() == ERROR_INVALID_HANDLE),
"returned %p with 0x%08lx (expected %p with ERROR_INVALID_HANDLE)\n", "returned %p with 0x%08lx (expected %p with ERROR_INVALID_HANDLE)\n",
hsecond, GetLastError(), gbl); hsecond, GetLastError(), gbl);
SetLastError(MAGIC_DEAD);
flags = GlobalFlags(gbl);
ok( (flags == GMEM_INVALID_HANDLE) && (GetLastError() == ERROR_INVALID_HANDLE),
"returned 0x%04x with 0x%08lx (expected GMEM_INVALID_HANDLE with " \
"ERROR_INVALID_HANDLE)\n", flags, GetLastError());
/* Local*() functions */ /* Local*() functions */
gbl = LocalAlloc(LMEM_MOVEABLE, 0); gbl = LocalAlloc(LMEM_MOVEABLE, 0);
@ -109,13 +116,19 @@ START_TEST(heap)
ok(gbl == NULL, "local realloc allocated memory\n"); ok(gbl == NULL, "local realloc allocated memory\n");
/* invalid handles are catched in windows */ /* invalid handles are catched in windows */
gbl = LocalAlloc(GMEM_MOVEABLE, 256); gbl = LocalAlloc(LMEM_MOVEABLE, 256);
LocalFree(gbl); LocalFree(gbl);
SetLastError(MAGIC_DEAD); SetLastError(MAGIC_DEAD);
hsecond = LocalFree(gbl); /* invalid handle: free memory twice */ hsecond = LocalFree(gbl); /* invalid handle: free memory twice */
ok( (hsecond == gbl) && (GetLastError() == ERROR_INVALID_HANDLE), ok( (hsecond == gbl) && (GetLastError() == ERROR_INVALID_HANDLE),
"returned %p with 0x%08lx (expected %p with ERROR_INVALID_HANDLE)\n", "returned %p with 0x%08lx (expected %p with ERROR_INVALID_HANDLE)\n",
hsecond, GetLastError(), gbl); hsecond, GetLastError(), gbl);
SetLastError(MAGIC_DEAD);
flags = LocalFlags(gbl);
ok( (flags == LMEM_INVALID_HANDLE) && (GetLastError() == ERROR_INVALID_HANDLE),
"returned 0x%04x with 0x%08lx (expected LMEM_INVALID_HANDLE with " \
"ERROR_INVALID_HANDLE)\n", flags, GetLastError());
/* trying to lock empty memory should give an error */ /* trying to lock empty memory should give an error */
gbl = GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT,0); gbl = GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT,0);