From: Stefan Leichter Subject: kernel32: check the last parameter of K32EnumProcessModules for NULL before use (with test) Message-Id: <201205171046.29006.Stefan.Leichter@camline.com> Date: Thu, 17 May 2012 10:46:28 +0200 See http://bugs.winehq.org/show_bug.cgi?id=30528 --- dlls/kernel32/module.c | 6 ++++++ dlls/psapi/tests/psapi_main.c | 9 +++++++++ 2 files changed, 15 insertions(+), 0 deletions(-) diff --git a/dlls/kernel32/module.c b/dlls/kernel32/module.c index adf8a99..9913f1b 100644 --- a/dlls/kernel32/module.c +++ b/dlls/kernel32/module.c @@ -1175,6 +1175,12 @@ BOOL WINAPI K32EnumProcessModules(HANDLE process, HMODULE *lphModule, if (!init_module_iterator(&iter, process)) return FALSE; + if (!needed) + { + SetLastError(ERROR_NOACCESS); + return FALSE; + } + *needed = 0; while ((ret = module_iterator_next(&iter)) > 0) diff --git a/dlls/psapi/tests/psapi_main.c b/dlls/psapi/tests/psapi_main.c index 8db695e..d8f01b4 100644 --- a/dlls/psapi/tests/psapi_main.c +++ b/dlls/psapi/tests/psapi_main.c @@ -117,6 +117,15 @@ static void test_EnumProcessModules(void) ok(GetLastError() == ERROR_ACCESS_DENIED, "expected error=ERROR_ACCESS_DENIED but got %d\n", GetLastError()); SetLastError(0xdeadbeef); + pEnumProcessModules(hpQI, &hMod, sizeof(HMODULE), NULL); + ok(GetLastError() == ERROR_ACCESS_DENIED, "expected error=ERROR_ACCESS_DENIED but got %d\n", GetLastError()); + + SetLastError(0xdeadbeef); + ret = pEnumProcessModules(hpQV, &hMod, sizeof(HMODULE), NULL); + ok(!ret, "succeeded\n"); + ok(GetLastError() == ERROR_NOACCESS, "expected error=ERROR_NOACCESS but got %d\n", GetLastError()); + + SetLastError(0xdeadbeef); ret = pEnumProcessModules(hpQV, NULL, 0, &cbNeeded); ok(ret == 1, "failed with %d\n", GetLastError());