From 42f5ecd4a116c96d30bf407859dadaa9a053ea39 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 6 Nov 2015 09:24:18 +0100 Subject: util/StringCompare: use strncmp() instead of memcmp() in StringStartsWith() Some optimized implementations of memcmp() may not start from the beginning of the string, and may thus segfault. --- src/util/StringCompare.cxx | 4 ++-- src/util/WStringCompare.cxx | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/util/StringCompare.cxx b/src/util/StringCompare.cxx index a7e505d12..fbd8e1d6d 100644 --- a/src/util/StringCompare.cxx +++ b/src/util/StringCompare.cxx @@ -36,8 +36,8 @@ bool StringStartsWith(const char *haystack, const char *needle) { - const size_t length = strlen(needle); - return memcmp(haystack, needle, length) == 0; + const size_t length = StringLength(needle); + return StringIsEqual(haystack, needle, length); } bool diff --git a/src/util/WStringCompare.cxx b/src/util/WStringCompare.cxx index 77c3a8629..723f7e47b 100644 --- a/src/util/WStringCompare.cxx +++ b/src/util/WStringCompare.cxx @@ -26,7 +26,8 @@ bool StringStartsWith(const wchar_t *haystack, const wchar_t *needle) { - return memcmp(haystack, needle, StringLength(needle) * sizeof(needle[0])) == 0; + const size_t length = StringLength(needle); + return StringIsEqual(haystack, needle, length); } bool -- cgit v1.2.3