From: Katy Feng Date: Fri, 23 Dec 2022 00:25:50 +0000 (-0800) Subject: Linux guest identification: Make the code more robust X-Git-Tag: stable-12.2.0~25 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4a2332747dc9e95e7b93d2b6d28b1d7fd474e3f2;p=thirdparty%2Fopen-vm-tools.git Linux guest identification: Make the code more robust Additional clean up. --- diff --git a/open-vm-tools/lib/misc/hostinfoPosix.c b/open-vm-tools/lib/misc/hostinfoPosix.c index 7e33c670d..e1e1f5d3c 100644 --- a/open-vm-tools/lib/misc/hostinfoPosix.c +++ b/open-vm-tools/lib/misc/hostinfoPosix.c @@ -1412,7 +1412,7 @@ HostinfoReadDistroFile(Bool osReleaseRules, // IN: osRelease rules char lineBuf[DISTRO_BUF_SIZE]; FILE *s = NULL; uint32 nArgs = 0; - Bool first = TRUE; + Bool any = FALSE; Bool success = FALSE; char **result = NULL; char *distroOrig = NULL; @@ -1458,7 +1458,7 @@ HostinfoReadDistroFile(Bool osReleaseRules, // IN: osRelease rules /* * Attempt to parse a file with one name=value pair per line. Values are - * expected to embedded in double quotes. + * expected to be embedded in double quotes. */ nArgs = 0; @@ -1499,21 +1499,21 @@ HostinfoReadDistroFile(Bool osReleaseRules, // IN: osRelease rules *p = '\0'; - if (p - data > MAX_DETAILED_FIELD_LEN) { + if (p >= &data[MAX_DETAILED_FIELD_LEN]) { Warning("%s: Unexpectedly long data encountered; truncated.", __FUNCTION__); - p[MAX_DETAILED_FIELD_LEN - 1] = '\0'; + data[MAX_DETAILED_FIELD_LEN - 1] = '\0'; } - if (!first) { + if (any) { DynBuf_Strcat(&b, " "); } DynBuf_Strcat(&b, data); result[i] = Util_SafeStrdup(data); - first = FALSE; + any = TRUE; } } }