Commit 7ddd79b8 authored by Paul Gofman's avatar Paul Gofman Committed by Alexandre Julliard

kernelbase: Sanitize flags in GetModuleHandleExW().

parent cf0a828b
......@@ -1011,6 +1011,23 @@ static void testGetModuleHandleEx(void)
ok( error == ERROR_MOD_NOT_FOUND, "got %u\n", error );
ok( mod == NULL, "got %p\n", mod );
SetLastError( 0xdeadbeef );
mod = (HMODULE)0xdeadbeef;
ret = GetModuleHandleExW( GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT
| GET_MODULE_HANDLE_EX_FLAG_PIN, (LPCWSTR)mod_kernel32, &mod );
error = GetLastError();
ok( !ret, "unexpected success\n" );
ok( error == ERROR_INVALID_PARAMETER, "got %u\n", error );
ok( mod == NULL, "got %p\n", mod );
SetLastError( 0xdeadbeef );
mod = (HMODULE)0xdeadbeef;
ret = GetModuleHandleExW( 8, kernel32W, &mod );
error = GetLastError();
ok( !ret, "unexpected success\n" );
ok( error == ERROR_INVALID_PARAMETER, "got %u\n", error );
ok( mod == NULL, "got %p\n", mod );
FreeLibrary( mod_kernel32 );
}
......
......@@ -384,6 +384,16 @@ BOOL WINAPI DECLSPEC_HOTPATCH GetModuleHandleExW( DWORD flags, LPCWSTR name, HMO
return FALSE;
}
if ((flags & ~(GET_MODULE_HANDLE_EX_FLAG_PIN | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT
| GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS))
|| (flags & (GET_MODULE_HANDLE_EX_FLAG_PIN | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT))
== (GET_MODULE_HANDLE_EX_FLAG_PIN | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT))
{
*module = NULL;
SetLastError( ERROR_INVALID_PARAMETER );
return FALSE;
}
/* if we are messing with the refcount, grab the loader lock */
lock = (flags & GET_MODULE_HANDLE_EX_FLAG_PIN) || !(flags & GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT);
if (lock) LdrLockLoaderLock( 0, NULL, &magic );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment