diff options
author | Tad Marshall <tad@10gen.com> | 2013-07-19 10:51:02 -0400 |
---|---|---|
committer | Tad Marshall <tad@10gen.com> | 2013-07-19 11:48:41 -0400 |
commit | 228ad77a39a471b323095691dbbe1a9fd7150f38 (patch) | |
tree | 43f9578388d3f56f9a723d8743bd1bd2de1dc0d3 /src | |
parent | d2b2f42b5012c64468ab7ab24b137f4828b2405d (diff) | |
download | mongo-228ad77a39a471b323095691dbbe1a9fd7150f38.tar.gz |
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.
Diffstat (limited to 'src')
-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__) |