From 68f519ed6c9f84446a6efff8f40e03ef830e15cb Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Tue, 29 Oct 2019 11:29:47 +0100 Subject: [PATCH] Fixed length checks for GetComputerNameA --- winpr/libwinpr/sysinfo/sysinfo.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/winpr/libwinpr/sysinfo/sysinfo.c b/winpr/libwinpr/sysinfo/sysinfo.c index 3f984f7fe..c2667fe7f 100644 --- a/winpr/libwinpr/sysinfo/sysinfo.c +++ b/winpr/libwinpr/sysinfo/sysinfo.c @@ -391,7 +391,7 @@ BOOL GetVersionExW(LPOSVERSIONINFOW lpVersionInformation) BOOL GetComputerNameA(LPSTR lpBuffer, LPDWORD lpnSize) { char* dot; - int length; + size_t length; char hostname[256]; if (!lpnSize) @@ -403,22 +403,22 @@ BOOL GetComputerNameA(LPSTR lpBuffer, LPDWORD lpnSize) if (gethostname(hostname, sizeof(hostname)) == -1) return FALSE; - length = (int) strlen(hostname); + length = strnlen(hostname, sizeof(hostname)); dot = strchr(hostname, '.'); if (dot) - length = (int)(dot - hostname); + length = (dot - hostname); if ((*lpnSize <= (DWORD) length) || !lpBuffer) { SetLastError(ERROR_BUFFER_OVERFLOW); - *lpnSize = length + 1; + *lpnSize = (DWORD)(length + 1); return FALSE; } CopyMemory(lpBuffer, hostname, length); lpBuffer[length] = '\0'; - *lpnSize = length; + *lpnSize = (DWORD)length; return TRUE; }