Fix NULL defer in extended substition for \p, \P, or \X.

This commit is contained in:
Philip.Hazel 2016-12-09 16:57:51 +00:00
parent 6f3deee62d
commit bcad1aa4f6
4 changed files with 16 additions and 5 deletions

View File

@ -204,6 +204,10 @@ when the newline type is CRLF.
31. Fix a bug in pcre2test that caused a crash when a locale was set either in 31. Fix a bug in pcre2test that caused a crash when a locale was set either in
the current pattern or a previous one and a wide character was matched. the current pattern or a previous one and a wide character was matched.
32. The appearance of \p, \P, or \X in a substitution string when
PCRE2_SUBSTITUTE_EXTENDED was set caused a segmentation fault (NULL
dereference).
Version 10.22 29-July-2016 Version 10.22 29-July-2016
-------------------------- --------------------------

View File

@ -1352,10 +1352,10 @@ entry, ptr is pointing at the character after \. On exit, it points after the
final code unit of the escape sequence. final code unit of the escape sequence.
This function is also called from pcre2_substitute() to handle escape sequences This function is also called from pcre2_substitute() to handle escape sequences
in replacement strings. In this case, the cb argument is NULL, and only in replacement strings. In this case, the cb argument is NULL, and in the case
sequences that define a data character are recognised. The isclass argument is of escapes that have further processing, only sequences that define a data
not relevant, but the options argument is the final value of the compiled character are recognised. The isclass argument is not relevant; the options
pattern's options. argument is the final value of the compiled pattern's options.
Arguments: Arguments:
ptrptr points to the input position pointer ptrptr points to the input position pointer
@ -1405,7 +1405,7 @@ else if ((i = escapes[c - ESCAPES_FIRST]) != 0)
if (i > 0) c = (uint32_t)i; else /* Positive is a data character */ if (i > 0) c = (uint32_t)i; else /* Positive is a data character */
{ {
escape = -i; /* Else return a special escape */ escape = -i; /* Else return a special escape */
if (escape == ESC_P || escape == ESC_p || escape == ESC_X) if (cb != NULL && (escape == ESC_P || escape == ESC_p || escape == ESC_X))
cb->external_flags |= PCRE2_HASBKPORX; /* Note \P, \p, or \X */ cb->external_flags |= PCRE2_HASBKPORX; /* Note \P, \p, or \X */
} }
} }

3
testdata/testinput2 vendored
View File

@ -4925,4 +4925,7 @@ a)"xI
/./newline=crlf /./newline=crlf
\=ph \=ph
/(\x0e00\000000\xc)/replace=\P,substitute_extended
\x0e00\000000\xc
# End of testinput2 # End of testinput2

View File

@ -15378,6 +15378,10 @@ Failed: error 109 at offset 6: quantifier does not follow a repeatable item
\=ph \=ph
No match No match
/(\x0e00\000000\xc)/replace=\P,substitute_extended
\x0e00\000000\xc
Failed: error -57 at offset 2 in replacement: bad escape sequence in replacement string
# End of testinput2 # End of testinput2
Error -63: PCRE2_ERROR_BADDATA (unknown error number) Error -63: PCRE2_ERROR_BADDATA (unknown error number)
Error -62: bad serialized data Error -62: bad serialized data