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 ) ...@@ -55,13 +55,14 @@ GetUserNameA( LPSTR lpszName, LPDWORD lpSize )
{ {
WCHAR *buffer; WCHAR *buffer;
BOOL ret; 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 ); SetLastError( ERROR_NOT_ENOUGH_MEMORY );
return FALSE; return FALSE;
} }
ret = GetUserNameW( buffer, *lpSize * 2 ); ret = GetUserNameW( buffer, &sizeW );
if (ret) if (ret)
{ {
if (!(*lpSize = WideCharToMultiByte( CP_ACP, 0, buffer, -1, lpszName, *lpSize, NULL, NULL ))) if (!(*lpSize = WideCharToMultiByte( CP_ACP, 0, buffer, -1, lpszName, *lpSize, NULL, NULL )))
...@@ -71,6 +72,7 @@ GetUserNameA( LPSTR lpszName, LPDWORD lpSize ) ...@@ -71,6 +72,7 @@ GetUserNameA( LPSTR lpszName, LPDWORD lpSize )
ret = FALSE; ret = FALSE;
} }
} }
else *lpSize = sizeW * 2;
HeapFree( GetProcessHeap(), 0, buffer ); HeapFree( GetProcessHeap(), 0, buffer );
return ret; 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