Fix pcre2_substitute(): set zero-terminated length before UTF validity check.

This commit is contained in:
Philip.Hazel 2015-10-30 17:30:03 +00:00
parent 4b242c4c78
commit efccea98f1
4 changed files with 17 additions and 6 deletions

View File

@ -229,6 +229,10 @@ converted to use the new feature.
66. In the POSIX wrapper, if regerror() was given too small a buffer, it could
misbehave.
67. In pcre2_substitute() in UTF mode, the UTF validity check on the
replacement string was happening before the length setting when the replacement
string was zero-terminated.
Version 10.20 30-June-2015
--------------------------

View File

@ -227,6 +227,12 @@ if (match_data == NULL)
ovector = pcre2_get_ovector_pointer(match_data);
ovector_count = pcre2_get_ovector_count(match_data);
/* Find lengths of zero-terminated strings and the end of the replacement. */
if (length == PCRE2_ZERO_TERMINATED) length = PRIV(strlen)(subject);
if (rlength == PCRE2_ZERO_TERMINATED) rlength = PRIV(strlen)(replacement);
repend = replacement + rlength;
/* Check UTF replacement string if necessary. */
#ifdef SUPPORT_UNICODE
@ -256,12 +262,6 @@ if ((options & PCRE2_SUBSTITUTE_EXTENDED) != 0)
extended = TRUE;
}
/* Find lengths of zero-terminated strings and the end of the replacement. */
if (length == PCRE2_ZERO_TERMINATED) length = PRIV(strlen)(subject);
if (rlength == PCRE2_ZERO_TERMINATED) rlength = PRIV(strlen)(replacement);
repend = replacement + rlength;
/* Copy up to the start offset */
if (start_offset > buff_length) goto NOROOM;

3
testdata/testinput5 vendored
View File

@ -1686,4 +1686,7 @@
/(*UCP)(*UTF)[[:>:]]X/B
/abc/utf,replace=xyz
abc\=zero_terminate
# End of testinput5

View File

@ -4058,4 +4058,8 @@ No match
End
------------------------------------------------------------------
/abc/utf,replace=xyz
abc\=zero_terminate
1: xyz
# End of testinput5