Blame SOURCES/perl-5.28.1-regcomp.c-Convert-some-strchr-to-memchr.patch

b69025
From cc56be313c7d4e7c266c01dabc762a153d5b2c28 Mon Sep 17 00:00:00 2001
b69025
From: Karl Williamson <khw@cpan.org>
b69025
Date: Sat, 25 Mar 2017 15:00:22 -0600
b69025
Subject: [PATCH] regcomp.c: Convert some strchr to memchr
b69025
b69025
This allows things to work properly in the face of embedded NULs.
b69025
See the branch merge message for more information.
b69025
b69025
(cherry picked from commit 43b2f4ef399e2fd7240b4eeb0658686ad95f8e62)
b69025
---
b69025
 regcomp.c | 11 +++++++----
b69025
 1 file changed, 7 insertions(+), 4 deletions(-)
b69025
b69025
diff --git a/regcomp.c b/regcomp.c
b69025
index d0d08352c0..2bee9d4460 100644
b69025
--- a/regcomp.c
b69025
+++ b/regcomp.c
b69025
@@ -11793,7 +11793,8 @@ S_grok_bslash_N(pTHX_ RExC_state_t *pRExC_state,
b69025
 
b69025
     RExC_parse++;	/* Skip past the '{' */
b69025
 
b69025
-    if (! (endbrace = strchr(RExC_parse, '}'))  /* no trailing brace */
b69025
+    endbrace = (char *) memchr(RExC_parse, '}', RExC_end - RExC_parse);
b69025
+    if (! endbrace                             /* no trailing brace */
b69025
 	|| ! (endbrace == RExC_parse		/* nothing between the {} */
b69025
               || (endbrace - RExC_parse >= 2	/* U+ (bad hex is checked... */
b69025
                   && strnEQ(RExC_parse, "U+", 2)))) /* ... below for a better
b69025
@@ -12493,9 +12494,11 @@ S_regatom(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth)
b69025
             else {
b69025
                 STRLEN length;
b69025
                 char name = *RExC_parse;
b69025
-                char * endbrace;
b69025
+                char * endbrace = NULL;
b69025
                 RExC_parse += 2;
b69025
-                endbrace = strchr(RExC_parse, '}');
b69025
+                if (RExC_parse < RExC_end) {
b69025
+                    endbrace = (char *) memchr(RExC_parse, '}', RExC_end - RExC_parse);
b69025
+                }
b69025
 
b69025
                 if (! endbrace) {
b69025
                     vFAIL2("Missing right brace on \\%c{}", name);
b69025
@@ -15963,7 +15966,7 @@ S_regclass(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth,
b69025
 		    vFAIL2("Empty \\%c", (U8)value);
b69025
 		if (*RExC_parse == '{') {
b69025
 		    const U8 c = (U8)value;
b69025
-		    e = strchr(RExC_parse, '}');
b69025
+		    e = (char *) memchr(RExC_parse, '}', RExC_end - RExC_parse);
b69025
                     if (!e) {
b69025
                         RExC_parse++;
b69025
                         vFAIL2("Missing right brace on \\%c{}", c);
b69025
-- 
b69025
2.11.0
b69025