kernelbase: Fix string size variable overflow in GetModuleFileNameW().

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=51833
Signed-off-by: Paul Gofman <pgofman@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Paul Gofman 2021-10-04 12:21:10 +03:00 committed by Alexandre Julliard
parent 20fb14bf27
commit 7c523f4867
2 changed files with 6 additions and 1 deletions

View file

@ -190,6 +190,11 @@ static void testGetModuleFileName(const char* name)
ok(len1A / 2 == len2A,
"Correct length in GetModuleFilenameA with buffer too small (%d/%d)\n", len1A / 2, len2A);
len1A = GetModuleFileNameA(hMod, bufA, 0x10000);
ok(len1A > 0, "Getting module filename for handle %p\n", hMod);
len1W = GetModuleFileNameW(hMod, bufW, 0x10000);
ok(len1W > 0, "Getting module filename for handle %p\n", hMod);
}
static void testGetModuleFileName_Wrong(void)

View file

@ -311,7 +311,7 @@ DWORD WINAPI DECLSPEC_HOTPATCH GetModuleFileNameW( HMODULE module, LPWSTR filena
}
name.Buffer = filename;
name.MaximumLength = size * sizeof(WCHAR);
name.MaximumLength = min( size, UNICODE_STRING_MAX_CHARS ) * sizeof(WCHAR);
status = LdrGetDllFullName( module, &name );
if (!status || status == STATUS_BUFFER_TOO_SMALL) len = name.Length / sizeof(WCHAR);
SetLastError( RtlNtStatusToDosError( status ));