From 228ad77a39a471b323095691dbbe1a9fd7150f38 Mon Sep 17 00:00:00 2001 From: Tad Marshall Date: Fri, 19 Jul 2013 10:51:02 -0400 Subject: SERVER-10259 Do not return pointer into temporary string Convert the location found within the temporary string into the equivalent (and correct) location in the source string. --- src/mongo/platform/strcasestr.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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__) -- cgit v1.2.1