[KERNEL32] Fix 64 bit issues
[reactos.git] / dll / win32 / kernel32 / client / compname.c
index a336eaa..91860ce 100644 (file)
@@ -391,8 +391,15 @@ SetComputerNameToRegistry(LPCWSTR RegistryKey,
     UNICODE_STRING KeyName;
     UNICODE_STRING ValueName;
     HANDLE KeyHandle;
+    SIZE_T StringLength;
     NTSTATUS Status;
 
+    StringLength = wcslen(lpBuffer);
+    if (StringLength > ((MAXULONG / sizeof(WCHAR)) - 1))
+    {
+        return FALSE;
+    }
+
     RtlInitUnicodeString(&KeyName, RegistryKey);
     InitializeObjectAttributes(&ObjectAttributes,
                                &KeyName,
@@ -416,7 +423,7 @@ SetComputerNameToRegistry(LPCWSTR RegistryKey,
                            0,
                            REG_SZ,
                            (PVOID)lpBuffer,
-                           (wcslen (lpBuffer) + 1) * sizeof(WCHAR));
+                           (StringLength + 1) * sizeof(WCHAR));
     if (!NT_SUCCESS(Status))
     {
         NtClose(KeyHandle);