[KERNEL32]
[reactos.git] / reactos / dll / win32 / kernel32 / client / compname.c
index 06c11b6..3bed83d 100644 (file)
@@ -88,7 +88,7 @@ GetComputerNameFromRegistry(LPWSTR RegistryKey,
 
     if (!NT_SUCCESS(Status))
     {
-        *nSize = ReturnSize;
+        *nSize = (ReturnSize - FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data)) / sizeof(WCHAR);
         goto failed;
     }
 
@@ -100,7 +100,7 @@ GetComputerNameFromRegistry(LPWSTR RegistryKey,
 
     if (!lpBuffer || *nSize < (KeyInfo->DataLength / sizeof(WCHAR)))
     {
-        *nSize = ReturnSize;
+        *nSize = (ReturnSize - FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data)) / sizeof(WCHAR);
         Status = STATUS_BUFFER_OVERFLOW;
         goto failed;
     }
@@ -135,6 +135,13 @@ GetComputerNameExW(COMPUTER_NAME_FORMAT NameType,
     BOOL ret = TRUE;
     DWORD HostSize;
 
+    if ((nSize == NULL) ||
+        (lpBuffer == NULL && *nSize > 0))
+    {
+        SetLastError(ERROR_INVALID_PARAMETER);
+        return FALSE;
+    }
+
     switch (NameType)
     {
         case ComputerNameNetBIOS:
@@ -263,19 +270,23 @@ GetComputerNameExA(COMPUTER_NAME_FORMAT NameType,
     UNICODE_STRING UnicodeString;
     ANSI_STRING AnsiString;
     BOOL Result;
-    PWCHAR TempBuffer;
+    PWCHAR TempBuffer = NULL;
 
-    if (!lpBuffer)
+    if ((nSize == NULL) ||
+        (lpBuffer == NULL && *nSize > 0))
     {
         SetLastError(ERROR_INVALID_PARAMETER);
         return FALSE;
     }
 
-    TempBuffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, *nSize * sizeof(WCHAR));
-    if (!TempBuffer)
+    if (*nSize > 0)
     {
-        SetLastError(ERROR_NOT_ENOUGH_MEMORY);
-        return FALSE;
+        TempBuffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, *nSize * sizeof(WCHAR));
+        if (!TempBuffer)
+        {
+            SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+            return FALSE;
+        }
     }
 
     AnsiString.MaximumLength = (USHORT)*nSize;
@@ -287,7 +298,7 @@ GetComputerNameExA(COMPUTER_NAME_FORMAT NameType,
     if (Result)
     {
         UnicodeString.MaximumLength = (USHORT)*nSize * sizeof(WCHAR) + sizeof(WCHAR);
-        UnicodeString.Length = (USHORT)*nSize * sizeof(WCHAR) + sizeof(WCHAR);
+        UnicodeString.Length = (USHORT)*nSize * sizeof(WCHAR);
         UnicodeString.Buffer = TempBuffer;
 
         RtlUnicodeStringToAnsiString(&AnsiString,