From: Oliver Kurth Date: Wed, 11 Dec 2019 18:19:09 +0000 (-0800) Subject: Avoid vmtoolsd crash in HostInfo. X-Git-Tag: stable-11.0.5~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=85b51e8d8fecf8cb6e8408c977b98bb5e06b22f2;p=thirdparty%2Fopen-vm-tools.git Avoid vmtoolsd crash in HostInfo. The guest identification code causes vmtoolsd to crash in certain versions of some distros. The crash is caused by recent changes to the lsb_release command. Previously, if the command existed, all of its options worked. Now, some of the options no longer exist. Change the code to check for an lsb_release failure whenever it is invoked. Fix for: https://github.com/vmware/open-vm-tools/issues/390 --- diff --git a/open-vm-tools/lib/misc/hostinfoPosix.c b/open-vm-tools/lib/misc/hostinfoPosix.c index e7ae9d257..9d58abeec 100644 --- a/open-vm-tools/lib/misc/hostinfoPosix.c +++ b/open-vm-tools/lib/misc/hostinfoPosix.c @@ -284,13 +284,13 @@ HostinfoOSVersionInit(void) } version = Util_SafeCalloc(1, sizeof *version); - version->hostinfoOSVersionString = Util_SafeStrndup(u.release, + version->hostinfoOSVersionString = Util_SafeStrndup(u.release, sizeof u.release); ASSERT(ARRAYSIZE(version->hostinfoOSVersion) >= 4); /* - * The first three numbers are separated by '.', if there is + * The first three numbers are separated by '.', if there is * a fourth number, it's probably separated by '.' or '-', * but it could be preceded by anything. */ @@ -1334,6 +1334,8 @@ HostinfoLsbRemoveQuotes(char *lsbOutput) // IN/OUT: { char *lsbStart = lsbOutput; + ASSERT(lsbStart != NULL); + if (lsbStart[0] == '"') { char *quoteEnd = strchr(++lsbStart, '"'); @@ -1407,13 +1409,17 @@ HostinfoLsb(char ***args) // OUT: /* LSB Distributor */ lsbOutput = HostinfoGetCmdOutput("/usr/bin/lsb_release -si 2>/dev/null"); - (*args)[0] = Util_SafeStrdup(HostinfoLsbRemoveQuotes(lsbOutput)); - free(lsbOutput); + if (lsbOutput != NULL) { + (*args)[0] = Util_SafeStrdup(HostinfoLsbRemoveQuotes(lsbOutput)); + free(lsbOutput); + } /* LSB Release */ lsbOutput = HostinfoGetCmdOutput("/usr/bin/lsb_release -sr 2>/dev/null"); - (*args)[1] = Util_SafeStrdup(HostinfoLsbRemoveQuotes(lsbOutput)); - free(lsbOutput); + if (lsbOutput != NULL) { + (*args)[1] = Util_SafeStrdup(HostinfoLsbRemoveQuotes(lsbOutput)); + free(lsbOutput); + } /* LSB Description */ (*args)[3] = Util_SafeStrdup((*args)[fields]); @@ -3495,7 +3501,7 @@ NOT_IMPLEMENTED(); *---------------------------------------------------------------------- */ -static Bool +static Bool HostinfoFindEntry(char *buffer, // IN: Buffer char *string, // IN: String sought unsigned int *value) // OUT: Value @@ -3578,7 +3584,7 @@ HostinfoGetMemInfo(char *name, // IN: * HostinfoSysinfo -- * * Retrieve system information on a Linux system. - * + * * Results: * TRUE on success: '*totalRam', '*freeRam', '*totalSwap' and '*freeSwap' * are set if not NULL @@ -3624,7 +3630,7 @@ HostinfoSysinfo(uint64 *totalRam, // OUT: Total RAM in bytes if (sysinfo((struct sysinfo *)&si) < 0) { return FALSE; } - + if (si.mem_unit == 0) { /* * Kernel versions < 2.3.23. Those kernels used a smaller sysinfo @@ -3679,10 +3685,10 @@ HostinfoGetLinuxMemoryInfoInPages(unsigned int *minSize, // OUT: unsigned int *maxSize, // OUT: unsigned int *currentSize) // OUT: { - uint64 total; + uint64 total; uint64 free; unsigned int cached = 0; - + /* * Note that the free memory provided by linux does not include buffer and * cache memory. Linux tries to use the free memory to cache file. Most of @@ -3749,7 +3755,7 @@ Bool Hostinfo_GetSwapInfoInPages(unsigned int *totalSwap, // OUT: unsigned int *freeSwap) // OUT: { - uint64 total; + uint64 total; uint64 free; if (HostinfoSysinfo(NULL, NULL, &total, &free) == FALSE) { @@ -3838,7 +3844,7 @@ Hostinfo_GetMemoryInfoInPages(unsigned int *minSize, // OUT: *maxSize = memsize / PAGE_SIZE; return TRUE; #elif defined(VMX86_SERVER) - uint64 total; + uint64 total; uint64 free; VMK_ReturnStatus status;