summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTad Marshall <tad@10gen.com>2013-07-19 10:51:02 -0400
committerTad Marshall <tad@10gen.com>2013-07-19 11:52:30 -0400
commit0d74c378de2be46cd572417071e3685965234a5e (patch)
tree14b43888ab8811111d591dd66cf72b808b1aaa04
parent2dcd03ab378a92a356225e87c697e891a4393bd3 (diff)
downloadmongo-0d74c378de2be46cd572417071e3685965234a5e.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.
-rw-r--r--src/mongo/platform/strcasestr.cpp7
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__)