]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Fix StrUtil_StartsWith.
authorVMware, Inc <>
Tue, 24 Aug 2010 18:19:22 +0000 (11:19 -0700)
committerMarcelo Vanzin <mvanzin@vmware.com>
Tue, 24 Aug 2010 18:19:22 +0000 (11:19 -0700)
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 <mvanzin@vmware.com>
open-vm-tools/lib/misc/strutil.c

index 93050f4efa4a39b86188c36844dbd3ab992da0f4..64322f3d417572c253a1db943011b09b48275f2c 100644 (file)
@@ -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';
 }