[KERNEL32] SetComputerNameExW: Truncate the computer name

This fixes the SetComputerNameExW api test.
This commit is contained in:
Eric Kohl 2021-12-12 17:40:52 +01:00
parent 067c08c23f
commit cf8380100e

View file

@ -648,6 +648,7 @@ WINAPI
SetComputerNameExW(COMPUTER_NAME_FORMAT NameType, SetComputerNameExW(COMPUTER_NAME_FORMAT NameType,
LPCWSTR lpBuffer) LPCWSTR lpBuffer)
{ {
WCHAR szShortName[MAX_COMPUTERNAME_LENGTH + 1];
BOOL ret1, ret2; BOOL ret1, ret2;
if (!IsValidComputerName(NameType, lpBuffer)) if (!IsValidComputerName(NameType, lpBuffer))
@ -670,17 +671,19 @@ SetComputerNameExW(COMPUTER_NAME_FORMAT NameType,
L"NV Hostname", L"NV Hostname",
lpBuffer); lpBuffer);
RtlStringCchCopyNW(szShortName, ARRAYSIZE(szShortName), lpBuffer, MAX_COMPUTERNAME_LENGTH);
ret2 = SetComputerNameToRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet" ret2 = SetComputerNameToRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet"
L"\\Control\\ComputerName\\ComputerName", L"\\Control\\ComputerName\\ComputerName",
L"ComputerName", L"ComputerName",
lpBuffer); szShortName);
return (ret1 && ret2); return (ret1 && ret2);
case ComputerNamePhysicalNetBIOS: case ComputerNamePhysicalNetBIOS:
RtlStringCchCopyNW(szShortName, ARRAYSIZE(szShortName), lpBuffer, MAX_COMPUTERNAME_LENGTH);
return SetComputerNameToRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet" return SetComputerNameToRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet"
L"\\Control\\ComputerName\\ComputerName", L"\\Control\\ComputerName\\ComputerName",
L"ComputerName", L"ComputerName",
lpBuffer); szShortName);
default: default:
SetLastError(ERROR_INVALID_PARAMETER); SetLastError(ERROR_INVALID_PARAMETER);