diff --git a/reactos/dll/win32/kernel32/misc/computername.c b/reactos/dll/win32/kernel32/misc/computername.c index e5bf86c648d..b07e644ab09 100644 --- a/reactos/dll/win32/kernel32/misc/computername.c +++ b/reactos/dll/win32/kernel32/misc/computername.c @@ -92,11 +92,19 @@ GetComputerNameFromRegistry(LPWSTR RegistryKey, return FALSE; } - if (*nSize > (KeyInfo->DataLength / sizeof(WCHAR))) + if (lpBuffer && *nSize > (KeyInfo->DataLength / sizeof(WCHAR))) { *nSize = KeyInfo->DataLength / sizeof(WCHAR) - 1; lpBuffer[*nSize] = 0; } + else + { + RtlFreeHeap(RtlGetProcessHeap(), 0, KeyInfo); + ZwClose(KeyHandle); + *nSize = ReturnSize; + SetLastErrorByStatus(STATUS_BUFFER_OVERFLOW); + return FALSE; + } RtlCopyMemory(lpBuffer, KeyInfo->Data, *nSize * sizeof(WCHAR)); @@ -254,7 +262,8 @@ GetComputerNameExA(COMPUTER_NAME_FORMAT NameType, if (!TempBuffer) { - return ERROR_OUTOFMEMORY; + SetLastError(ERROR_NOT_ENOUGH_MEMORY); + return FALSE; } AnsiString.MaximumLength = (USHORT)*nSize;