strcasestr: check if ne[0] is in hs with strchr or strpbrk as does strstr

Message ID 20230906174230.306332-1-tirtajames45@gmail.com
State Dropped
Headers
Series strcasestr: check if ne[0] is in hs with strchr or strpbrk as does strstr |

Checks

Context Check Description
redhat-pt-bot/TryBot-apply_patch success Patch applied to master at the time it was sent
redhat-pt-bot/TryBot-32bit success Build for i686
linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_glibc_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_glibc_check--master-arm success Testing passed

Commit Message

James Tirta Halim Sept. 6, 2023, 5:42 p.m. UTC
  ---
 string/strcasestr.c | 8 ++++++++
 1 file changed, 8 insertions(+)
  

Patch

diff --git a/string/strcasestr.c b/string/strcasestr.c
index 2f6b4f8641..295cbf364d 100644
--- a/string/strcasestr.c
+++ b/string/strcasestr.c
@@ -67,6 +67,14 @@  STRCASESTR (const char *haystack, const char *needle)
   /* Handle empty NEEDLE special case.  */
   if (needle[0] == '\0')
     return (char *) haystack;
+  if (isalpha(*needle)) {
+    const char a[] = { tolower(*needle), toupper(*needle), '\0'};
+    haystack = strpbrk(haystack, a);
+  } else {
+    haystack = strchr(haystack, *needle);
+  }
+  if (haystack == NULL || needle[1] == '\0')
+    return (char *)haystack;
 
   /* Ensure HAYSTACK length is at least as long as NEEDLE length.
      Since a match may occur early on in a huge HAYSTACK, use strnlen