From fd11023e4b44b18af7f9d44b216bcc254fe3b299 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Tue, 1 May 2012 14:43:46 +0200 Subject: [PATCH] kernel32: Fix another overflow in GetModuleFileNameExW. --- dlls/kernel32/module.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/dlls/kernel32/module.c b/dlls/kernel32/module.c index 57a24ba1514..adf8a99e031 100644 --- a/dlls/kernel32/module.c +++ b/dlls/kernel32/module.c @@ -1255,18 +1255,20 @@ DWORD WINAPI K32GetModuleFileNameExW(HANDLE process, HMODULE module, return 0; len = ldr_module.FullDllName.Length / sizeof(WCHAR); - if (size <= len) - { - len = size; - size--; - } - if (!ReadProcessMemory(process, ldr_module.FullDllName.Buffer, - file_name, size * sizeof(WCHAR), NULL)) + file_name, min( len, size ) * sizeof(WCHAR), NULL)) return 0; - file_name[size] = 0; - return len; + if (len < size) + { + file_name[len] = 0; + return len; + } + else + { + file_name[size - 1] = 0; + return size; + } } /***********************************************************************