Skip to content

Commit 43b2f4e

Browse files
committed
regcomp.c: Convert some strchr to memchr
This allows things to work properly in the face of embedded NULs. See the branch merge message for more information.
1 parent aea1585 commit 43b2f4e

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

regcomp.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12056,7 +12056,7 @@ S_grok_bslash_N(pTHX_ RExC_state_t *pRExC_state,
1205612056

1205712057
RExC_parse++; /* Skip past the '{' */
1205812058

12059-
endbrace = strchr(RExC_parse, '}');
12059+
endbrace = (char *) memchr(RExC_parse, '}', RExC_end - RExC_parse);
1206012060
if (! endbrace) { /* no trailing brace */
1206112061
vFAIL2("Missing right brace on \\%c{}", 'N');
1206212062
}
@@ -12773,9 +12773,11 @@ S_regatom(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth)
1277312773
else {
1277412774
STRLEN length;
1277512775
char name = *RExC_parse;
12776-
char * endbrace;
12776+
char * endbrace = NULL;
1277712777
RExC_parse += 2;
12778-
endbrace = strchr(RExC_parse, '}');
12778+
if (RExC_parse < RExC_end) {
12779+
endbrace = (char *) memchr(RExC_parse, '}', RExC_end - RExC_parse);
12780+
}
1277912781

1278012782
if (! endbrace) {
1278112783
vFAIL2("Missing right brace on \\%c{}", name);
@@ -16312,7 +16314,7 @@ S_regclass(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth,
1631216314
vFAIL2("Empty \\%c", (U8)value);
1631316315
if (*RExC_parse == '{') {
1631416316
const U8 c = (U8)value;
16315-
e = strchr(RExC_parse, '}');
16317+
e = (char *) memchr(RExC_parse, '}', RExC_end - RExC_parse);
1631616318
if (!e) {
1631716319
RExC_parse++;
1631816320
vFAIL2("Missing right brace on \\%c{}", c);

0 commit comments

Comments
 (0)