From 270d68f94936f6b67d186c644480da1ff3d63d15 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Tue, 28 Feb 2017 09:39:04 +0100 Subject: [PATCH] Fixed setting of lpnSize according to spec. --- winpr/libwinpr/sysinfo/sysinfo.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/winpr/libwinpr/sysinfo/sysinfo.c b/winpr/libwinpr/sysinfo/sysinfo.c index 2c1d85c..33f2534 100644 --- a/winpr/libwinpr/sysinfo/sysinfo.c +++ b/winpr/libwinpr/sysinfo/sysinfo.c @@ -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: -- 2.7.4