diff options
-rw-r--r-- | src/mongo/platform/strcasestr.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/mongo/platform/strcasestr.cpp b/src/mongo/platform/strcasestr.cpp index 748f1bf0cca..1bcd0a37094 100644 --- a/src/mongo/platform/strcasestr.cpp +++ b/src/mongo/platform/strcasestr.cpp @@ -59,7 +59,12 @@ namespace pal { needleLower.begin(), ::tolower); - return strstr(haystackLower.c_str(), needleLower.c_str()); + // Use strstr() to find 'lowercased needle' in 'lowercased haystack' + // If found, use the location to compute the matching location in the original string + // If not found, return NULL + const char* haystackLowerStart = haystackLower.c_str(); + const char* location = strstr(haystackLowerStart, needleLower.c_str()); + return location ? (haystack + (location - haystackLowerStart)) : NULL; } #if defined(__sunos__) |