From 62e71e2fbeaaf76e1faa43ccc7a945c44463589e Mon Sep 17 00:00:00 2001 From: rsun3 Date: Fri, 8 May 2009 05:22:17 +0000 Subject: [PATCH] Fix bugs in StrStr() and AsciiStrStr(). git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@8261 6f19259b-4bc3-4df7-8a09-765794883524 --- MdePkg/Library/BaseLib/String.c | 37 ++++++++++++++++----------------- 1 file 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; -- 2.39.2