mirror of
https://github.com/reactos/reactos.git
synced 2025-08-11 13:35:33 +00:00
[KERNEL32]
* Properly check if buffer given to GetComputerName is too small. Fixes hostname.exe if computer name is MAX_COMPUTERNAME_LENGTH long (the default for bootcd since it's generated randomly in Setup). * Simplify it a bit svn path=/trunk/; revision=51412
This commit is contained in:
parent
be4bb69ef8
commit
a861f7c282
1 changed files with 33 additions and 28 deletions
|
@ -83,35 +83,40 @@ GetComputerNameFromRegistry(LPWSTR RegistryKey,
|
||||||
KeyInfo,
|
KeyInfo,
|
||||||
KeyInfoSize,
|
KeyInfoSize,
|
||||||
&ReturnSize);
|
&ReturnSize);
|
||||||
|
|
||||||
|
ZwClose(KeyHandle);
|
||||||
|
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
RtlFreeHeap(RtlGetProcessHeap(), 0, KeyInfo);
|
|
||||||
ZwClose(KeyHandle);
|
|
||||||
*nSize = ReturnSize;
|
*nSize = ReturnSize;
|
||||||
SetLastErrorByStatus(Status);
|
goto failed;
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lpBuffer && *nSize > (KeyInfo->DataLength / sizeof(WCHAR)))
|
if (KeyInfo->Type != REG_SZ)
|
||||||
{
|
{
|
||||||
|
Status = STATUS_UNSUCCESSFUL;
|
||||||
|
goto failed;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!lpBuffer || *nSize < (KeyInfo->DataLength / sizeof(WCHAR)))
|
||||||
|
{
|
||||||
|
*nSize = ReturnSize;
|
||||||
|
Status = STATUS_BUFFER_OVERFLOW;
|
||||||
|
goto failed;
|
||||||
|
}
|
||||||
|
|
||||||
*nSize = KeyInfo->DataLength / sizeof(WCHAR) - 1;
|
*nSize = KeyInfo->DataLength / sizeof(WCHAR) - 1;
|
||||||
|
RtlCopyMemory(lpBuffer, KeyInfo->Data, KeyInfo->DataLength);
|
||||||
lpBuffer[*nSize] = 0;
|
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));
|
|
||||||
|
|
||||||
RtlFreeHeap(RtlGetProcessHeap(), 0, KeyInfo);
|
RtlFreeHeap(RtlGetProcessHeap(), 0, KeyInfo);
|
||||||
ZwClose(KeyHandle);
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
|
failed:
|
||||||
|
RtlFreeHeap(RtlGetProcessHeap(), 0, KeyInfo);
|
||||||
|
SetLastErrorByStatus(Status);
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue