summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrsun3 <rsun3@6f19259b-4bc3-4df7-8a09-765794883524>2009-05-08 05:22:17 +0000
committerrsun3 <rsun3@6f19259b-4bc3-4df7-8a09-765794883524>2009-05-08 05:22:17 +0000
commit62e71e2fbeaaf76e1faa43ccc7a945c44463589e (patch)
treefd9225b95f44a8725e99425f66f8c587916e999d
parent130a2eecc44b762345d5ff704e9d599b25e0f091 (diff)
downloadedk2-platforms-62e71e2fbeaaf76e1faa43ccc7a945c44463589e.tar.xz
Fix bugs in StrStr() and AsciiStrStr().
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@8261 6f19259b-4bc3-4df7-8a09-765794883524
-rw-r--r--MdePkg/Library/BaseLib/String.c37
1 files changed, 18 insertions, 19 deletions
diff --git a/MdePkg/Library/BaseLib/String.c b/MdePkg/Library/BaseLib/String.c
index 6717308473..50253de04f 100644
--- a/MdePkg/Library/BaseLib/String.c
+++ b/MdePkg/Library/BaseLib/String.c
@@ -478,29 +478,29 @@ StrStr (
ASSERT (StrSize (String) != 0);
ASSERT (StrSize (SearchString) != 0);
- while (*String != '\0') {
+ if (*SearchString == L'\0') {
+ return NULL;
+ }
+
+ while (*String != L'\0') {
SearchStringTmp = SearchString;
FirstMatch = String;
while ((*String == *SearchStringTmp)
- && (*SearchStringTmp != '\0')
- && (*String != '\0')) {
+ && (*String != L'\0')) {
String++;
SearchStringTmp++;
}
- if (*SearchStringTmp == '\0') {
+ if (*SearchStringTmp == L'\0') {
return (CHAR16 *) FirstMatch;
}
- if (SearchStringTmp == SearchString) {
- //
- // If no character from SearchString match,
- // move the pointer to the String under search
- // by one character.
- //
- String++;
+ if (*String == L'\0') {
+ return NULL;
}
+
+ String = FirstMatch + 1;
}
return NULL;
@@ -1616,12 +1616,15 @@ AsciiStrStr (
ASSERT (AsciiStrSize (String) != 0);
ASSERT (AsciiStrSize (SearchString) != 0);
+ if (*SearchString == '\0') {
+ return NULL;
+ }
+
while (*String != '\0') {
SearchStringTmp = SearchString;
FirstMatch = String;
while ((*String == *SearchStringTmp)
- && (*SearchStringTmp != '\0')
&& (*String != '\0')) {
String++;
SearchStringTmp++;
@@ -1631,15 +1634,11 @@ AsciiStrStr (
return (CHAR8 *) FirstMatch;
}
- if (SearchStringTmp == SearchString) {
- //
- // If no character from SearchString match,
- // move the pointer to the String under search
- // by one character.
- //
- String++;
+ if (*String == '\0') {
+ return NULL;
}
+ String = FirstMatch + 1;
}
return NULL;