Commit 6ddfba14 authored by Alexandre Julliard's avatar Alexandre Julliard

Fixed buffer size handling in GetUserNameA (reported by Hannu

Valtonen).
parent d19e2646
......@@ -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;
}
......
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