diff --git a/src/pcre2_compile.c b/src/pcre2_compile.c index aab3c4bd8..30b85d967 100644 --- a/src/pcre2_compile.c +++ b/src/pcre2_compile.c @@ -2707,7 +2707,7 @@ int i; if (ptr >= ptrend || *ptr != CHAR_LEFT_PARENTHESIS) { - *errorcodeptr = ERR15; + *errorcodeptr = ERR118; goto FAILED; } @@ -2716,6 +2716,12 @@ for (;;) ptr++; next_offset = (PCRE2_SIZE)(ptr - cb->start_pattern); + if (ptr >= ptrend) + { + *errorcodeptr = ERR117; + goto FAILED; + } + /* Handle [+-]number cases */ if (read_number(&ptr, ptrend, cb->bracount, MAX_GROUP_NUMBER, ERR61, &i, errorcodeptr)) @@ -2732,8 +2738,6 @@ for (;;) else if (*errorcodeptr != 0) goto FAILED; /* Number too big */ else { - if (ptr >= ptrend) goto UNCLOSED_PARENTHESIS; - /* Handle 'name' or cases. */ if (*ptr == CHAR_LESS_THAN_SIGN) terminator = CHAR_GREATER_THAN_SIGN; @@ -2741,7 +2745,7 @@ for (;;) terminator = CHAR_APOSTROPHE; else { - *errorcodeptr = ERR15; + *errorcodeptr = ERR117; goto FAILED; } @@ -4767,8 +4771,7 @@ while (ptr < ptrend) goto NEGATIVE_LOOK_AHEAD; case META_SCS: - if (++ptr >= ptrend) goto UNCLOSED_PARENTHESIS; - + ptr++; *parsed_pattern++ = META_SCS; parsed_pattern = parse_capture_list(&ptr, ptrend, utf, parsed_pattern, diff --git a/src/pcre2_compile.h b/src/pcre2_compile.h index 1fd53dd9d..dcf144a79 100644 --- a/src/pcre2_compile.h +++ b/src/pcre2_compile.h @@ -51,18 +51,18 @@ pcre2.h.in must be updated - their values are exactly 100 greater than these values. */ enum { ERR0 = COMPILE_ERROR_BASE, - ERR1, ERR2, ERR3, ERR4, ERR5, ERR6, ERR7, ERR8, ERR9, ERR10, - ERR11, ERR12, ERR13, ERR14, ERR15, ERR16, ERR17, ERR18, ERR19, ERR20, - ERR21, ERR22, ERR23, ERR24, ERR25, ERR26, ERR27, ERR28, ERR29, ERR30, - ERR31, ERR32, ERR33, ERR34, ERR35, ERR36, ERR37, ERR38, ERR39, ERR40, - ERR41, ERR42, ERR43, ERR44, ERR45, ERR46, ERR47, ERR48, ERR49, ERR50, - ERR51, ERR52, ERR53, ERR54, ERR55, ERR56, ERR57, ERR58, ERR59, ERR60, - ERR61, ERR62, ERR63, ERR64, ERR65, ERR66, ERR67, ERR68, ERR69, ERR70, - ERR71, ERR72, ERR73, ERR74, ERR75, ERR76, ERR77, ERR78, ERR79, ERR80, - ERR81, ERR82, ERR83, ERR84, ERR85, ERR86, ERR87, ERR88, ERR89, ERR90, - ERR91, ERR92, ERR93, ERR94, ERR95, ERR96, ERR97, ERR98, ERR99, ERR100, - ERR101,ERR102,ERR103,ERR104,ERR105,ERR106,ERR107,ERR108,ERR109,ERR110, - ERR111,ERR112,ERR113,ERR114,ERR115,ERR116 }; + ERR1, ERR2, ERR3, ERR4, ERR5, ERR6, ERR7, ERR8, ERR9, ERR10, + ERR11, ERR12, ERR13, ERR14, ERR15, ERR16, ERR17, ERR18, ERR19, ERR20, + ERR21, ERR22, ERR23, ERR24, ERR25, ERR26, ERR27, ERR28, ERR29, ERR30, + ERR31, ERR32, ERR33, ERR34, ERR35, ERR36, ERR37, ERR38, ERR39, ERR40, + ERR41, ERR42, ERR43, ERR44, ERR45, ERR46, ERR47, ERR48, ERR49, ERR50, + ERR51, ERR52, ERR53, ERR54, ERR55, ERR56, ERR57, ERR58, ERR59, ERR60, + ERR61, ERR62, ERR63, ERR64, ERR65, ERR66, ERR67, ERR68, ERR69, ERR70, + ERR71, ERR72, ERR73, ERR74, ERR75, ERR76, ERR77, ERR78, ERR79, ERR80, + ERR81, ERR82, ERR83, ERR84, ERR85, ERR86, ERR87, ERR88, ERR89, ERR90, + ERR91, ERR92, ERR93, ERR94, ERR95, ERR96, ERR97, ERR98, ERR99, ERR100, + ERR101, ERR102, ERR103, ERR104, ERR105, ERR106, ERR107, ERR108, ERR109, ERR110, + ERR111, ERR112, ERR113, ERR114, ERR115, ERR116, ERR117, ERR118 }; /* Code values for parsed patterns, which are stored in a vector of 32-bit unsigned ints. Values less than META_END are literal data values. The coding diff --git a/src/pcre2_error.c b/src/pcre2_error.c index dcb49b8d5..9e2e89d28 100644 --- a/src/pcre2_error.c +++ b/src/pcre2_error.c @@ -206,6 +206,8 @@ static const unsigned char compile_error_texts[] = /* 115 */ "terminating ] with no following closing parenthesis in (?[...]\0" "unexpected character in (?[...]) extended character class\0" + "expected capture group number or name\0" + "missing opening parenthesis\0" ; /* Match-time and UTF error texts are in the same format. */ diff --git a/testdata/testinput2 b/testdata/testinput2 index 7fa065442..dc15c63b6 100644 --- a/testdata/testinput2 +++ b/testdata/testinput2 @@ -7838,6 +7838,8 @@ a)"xI /(?1:1/ +/(?R:(1/ + /(?R:(1,/ /(?R0:(1,2!/ diff --git a/testdata/testoutput2 b/testdata/testoutput2 index 427f01f78..421cd31d5 100644 --- a/testdata/testoutput2 +++ b/testdata/testoutput2 @@ -18812,10 +18812,10 @@ No match # Parse errors first /(*scs:/ -Failed: error 114 at offset 6: missing closing parenthesis +Failed: error 218 at offset 6: missing opening parenthesis /(*scan_substring:(/ -Failed: error 114 at offset 18: missing closing parenthesis +Failed: error 217 at offset 18: expected capture group number or name /(*scs:('name'/ Failed: error 114 at offset 13: missing closing parenthesis @@ -21885,13 +21885,16 @@ Failed: error -69: error performing replacement case transformation # Parse error tests /(?1:/ -Failed: error 115 at offset 4: reference to non-existent subpattern +Failed: error 218 at offset 4: missing opening parenthesis /(?1:1/ -Failed: error 115 at offset 4: reference to non-existent subpattern +Failed: error 218 at offset 4: missing opening parenthesis + +/(?R:(1/ +Failed: error 114 at offset 6: missing closing parenthesis /(?R:(1,/ -Failed: error 114 at offset 7: missing closing parenthesis +Failed: error 217 at offset 7: expected capture group number or name /(?R0:(1,2!/ Failed: error 158 at offset 3: (?R (recursive pattern call) must be followed by a closing parenthesis