Fixed setting of lpnSize according to spec.
authorArmin Novak <armin.novak@thincast.com>
Tue, 28 Feb 2017 08:39:04 +0000 (09:39 +0100)
committerArmin Novak <armin.novak@thincast.com>
Tue, 28 Feb 2017 08:39:04 +0000 (09:39 +0100)
winpr/libwinpr/sysinfo/sysinfo.c

index 2c1d85c..33f2534 100644 (file)
@@ -409,16 +409,13 @@ BOOL GetComputerNameA(LPSTR lpBuffer, LPDWORD lpnSize)
        if (dot)
                length = (int)(dot - hostname);
 
-       if (*lpnSize <= (DWORD) length)
+       if ((*lpnSize <= (DWORD) length) || !lpBuffer)
        {
                SetLastError(ERROR_BUFFER_OVERFLOW);
                *lpnSize = length + 1;
                return FALSE;
        }
 
-       if (!lpBuffer)
-               return FALSE;
-
        CopyMemory(lpBuffer, hostname, length);
        lpBuffer[length] = '\0';
        *lpnSize = length;
@@ -462,18 +459,16 @@ BOOL GetComputerNameExA(COMPUTER_NAME_FORMAT NameType, LPSTR lpBuffer, LPDWORD l
            case ComputerNamePhysicalDnsHostname:
            case ComputerNamePhysicalDnsDomain:
            case ComputerNamePhysicalDnsFullyQualified:
-                   if (*lpnSize <= (DWORD) length)
+                       if ((*lpnSize <= (DWORD) length) || !lpBuffer)
                        {
                                *lpnSize = length + 1;
                                SetLastError(ERROR_MORE_DATA);
                                return FALSE;
                        }
 
-                       if (!lpBuffer)
-                               return FALSE;
-
                        CopyMemory(lpBuffer, hostname, length);
                        lpBuffer[length] = '\0';
+                       *lpnSize = length;
                    break;
 
            default: