Fix data overrun for /(?(?C)/

This commit is contained in:
Philip.Hazel 2015-03-20 12:37:28 +00:00
parent aa8d7342da
commit b15698b077
7 changed files with 25 additions and 7 deletions

View File

@ -8,6 +8,10 @@ Version 10.20 xx-xx-2015
2. Assertion code generator in JIT has been optimized. 2. Assertion code generator in JIT has been optimized.
3. The invalid pattern (?(?C) has a missing assertion condition at the end. The
pcre2_compile() function read past the end of the input before diagnosing an
error.
Version 10.10 06-March-2015 Version 10.10 06-March-2015
--------------------------- ---------------------------

View File

@ -5252,6 +5252,15 @@ for (;; ptr++)
} }
} }
} }
/* tempptr should now be pointing to the opening parenthesis of the
assertion condition. */
if (*tempptr != CHAR_LEFT_PARENTHESIS)
{
*errorcodeptr = ERR28;
goto FAILED;
}
} }
/* For conditions that are assertions, check the syntax, and then exit /* For conditions that are assertions, check the syntax, and then exit

View File

@ -97,7 +97,7 @@ static const char compile_error_texts[] =
"lookbehind assertion is not fixed length\0" "lookbehind assertion is not fixed length\0"
"malformed number or name after (?(\0" "malformed number or name after (?(\0"
"conditional group contains more than two branches\0" "conditional group contains more than two branches\0"
"assertion expected after (?(\0" "assertion expected after (?( or (?(?C)\0"
"(?R or (?[+-]digits must be followed by )\0" "(?R or (?[+-]digits must be followed by )\0"
/* 30 */ /* 30 */
"unknown POSIX class name\0" "unknown POSIX class name\0"

View File

@ -216,8 +216,8 @@ if ((cflags & REG_UTF) != 0) options |= PCRE2_UTF;
if ((cflags & REG_UCP) != 0) options |= PCRE2_UCP; if ((cflags & REG_UCP) != 0) options |= PCRE2_UCP;
if ((cflags & REG_UNGREEDY) != 0) options |= PCRE2_UNGREEDY; if ((cflags & REG_UNGREEDY) != 0) options |= PCRE2_UNGREEDY;
preg->re_pcre2_code = pcre2_compile((PCRE2_SPTR)pattern, -1, options, preg->re_pcre2_code = pcre2_compile((PCRE2_SPTR)pattern, PCRE2_ZERO_TERMINATED,
&errorcode, &erroffset, NULL); options, &errorcode, &erroffset, NULL);
preg->re_erroffset = erroffset; preg->re_erroffset = erroffset;
if (preg->re_pcre2_code == NULL) if (preg->re_pcre2_code == NULL)

View File

@ -90,4 +90,6 @@
/abc/\ /abc/\
"(?(?C)"
# End of testdata/testinput16 # End of testdata/testinput16

View File

@ -142,4 +142,7 @@ No match: POSIX code 17: match failed
/abc/\ /abc/\
Failed: POSIX code 9: bad escape sequence at offset 4 Failed: POSIX code 9: bad escape sequence at offset 4
"(?(?C)"
Failed: POSIX code 3: pattern error at offset 2
# End of testdata/testinput16 # End of testdata/testinput16

View File

@ -567,7 +567,7 @@ Failed: error 126 at offset 4: malformed number or name after (?(
Failed: error 126 at offset 4: malformed number or name after (?( Failed: error 126 at offset 4: malformed number or name after (?(
/(?(?i))/ /(?(?i))/
Failed: error 128 at offset 3: assertion expected after (?( Failed: error 128 at offset 3: assertion expected after (?( or (?(?C)
/(?(abc))/ /(?(abc))/
Failed: error 115 at offset 7: reference to non-existent subpattern Failed: error 115 at offset 7: reference to non-existent subpattern
@ -7367,7 +7367,7 @@ No match
Failed: error 126 at offset 6: malformed number or name after (?( Failed: error 126 at offset 6: malformed number or name after (?(
/(?(''))/ /(?(''))/
Failed: error 128 at offset 4: assertion expected after (?( Failed: error 128 at offset 4: assertion expected after (?( or (?(?C)
/(?('R')stuff)/ /(?('R')stuff)/
Failed: error 115 at offset 7: reference to non-existent subpattern Failed: error 115 at offset 7: reference to non-existent subpattern