From: VMware, Inc <> Date: Tue, 24 Aug 2010 18:19:22 +0000 (-0700) Subject: Fix StrUtil_StartsWith. X-Git-Tag: 2010.08.24-292196~54 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7f274e70941555ee15b38e17d2be7b24ccbd561e;p=thirdparty%2Fopen-vm-tools.git Fix StrUtil_StartsWith. When the two strings diverge at the last non-NUL byte of the prefix string, or at the byte preceding a trailing path separator, the functions incorrectly return TRUE. Signed-off-by: Marcelo Vanzin --- diff --git a/open-vm-tools/lib/misc/strutil.c b/open-vm-tools/lib/misc/strutil.c index 93050f4ef..64322f3d4 100644 --- a/open-vm-tools/lib/misc/strutil.c +++ b/open-vm-tools/lib/misc/strutil.c @@ -714,7 +714,12 @@ StrUtil_StartsWith(const char *s, // IN ASSERT(s != NULL); ASSERT(prefix != NULL); - return Str_Strncmp(s, prefix, strlen(prefix)) == 0; + while (*prefix && *prefix == *s) { + prefix++; + s++; + } + + return *prefix == '\0'; }