From 6ddfba14e29a9d9734526ba0253e5808d7a4057d Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Mon, 10 May 2004 21:26:58 +0000 Subject: [PATCH] Fixed buffer size handling in GetUserNameA (reported by Hannu Valtonen). --- dlls/advapi32/advapi.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/dlls/advapi32/advapi.c b/dlls/advapi32/advapi.c index e00eddeece6..f6a922b4754 100644 --- a/dlls/advapi32/advapi.c +++ b/dlls/advapi32/advapi.c @@ -55,13 +55,14 @@ GetUserNameA( LPSTR lpszName, LPDWORD lpSize ) { WCHAR *buffer; BOOL ret; + DWORD sizeW = *lpSize * 2; - if (!(buffer = HeapAlloc( GetProcessHeap(), 0, *lpSize * 2 * sizeof(WCHAR) ))) + if (!(buffer = HeapAlloc( GetProcessHeap(), 0, sizeW * sizeof(WCHAR) ))) { SetLastError( ERROR_NOT_ENOUGH_MEMORY ); return FALSE; } - ret = GetUserNameW( buffer, *lpSize * 2 ); + ret = GetUserNameW( buffer, &sizeW ); if (ret) { if (!(*lpSize = WideCharToMultiByte( CP_ACP, 0, buffer, -1, lpszName, *lpSize, NULL, NULL ))) @@ -71,6 +72,7 @@ GetUserNameA( LPSTR lpszName, LPDWORD lpSize ) ret = FALSE; } } + else *lpSize = sizeW * 2; HeapFree( GetProcessHeap(), 0, buffer ); return ret; }