[Pcre-svn] [400] code/trunk: Fix pcre2_substitute(): set ze…

トップ ページ
このメッセージを削除
著者: Subversion repository
日付:  
To: pcre-svn
題目: [Pcre-svn] [400] code/trunk: Fix pcre2_substitute(): set zero-terminated length before UTF validity check.
Revision: 400
          http://www.exim.org/viewvc/pcre2?view=rev&revision=400
Author:   ph10
Date:     2015-10-30 17:30:03 +0000 (Fri, 30 Oct 2015)
Log Message:
-----------
Fix pcre2_substitute(): set zero-terminated length before UTF validity check.


Modified Paths:
--------------
    code/trunk/ChangeLog
    code/trunk/src/pcre2_substitute.c
    code/trunk/testdata/testinput5
    code/trunk/testdata/testoutput5


Modified: code/trunk/ChangeLog
===================================================================
--- code/trunk/ChangeLog    2015-10-30 17:17:40 UTC (rev 399)
+++ code/trunk/ChangeLog    2015-10-30 17:30:03 UTC (rev 400)
@@ -229,7 +229,11 @@
 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
--------------------------


Modified: code/trunk/src/pcre2_substitute.c
===================================================================
--- code/trunk/src/pcre2_substitute.c    2015-10-30 17:17:40 UTC (rev 399)
+++ code/trunk/src/pcre2_substitute.c    2015-10-30 17:30:03 UTC (rev 400)
@@ -227,6 +227,12 @@
 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 @@
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;

Modified: code/trunk/testdata/testinput5
===================================================================
--- code/trunk/testdata/testinput5    2015-10-30 17:17:40 UTC (rev 399)
+++ code/trunk/testdata/testinput5    2015-10-30 17:30:03 UTC (rev 400)
@@ -1688,4 +1688,7 @@


/(*UCP)(*UTF)[[:>:]]X/B

+/abc/utf,replace=xyz
+    abc\=zero_terminate
+
 # End of testinput5 


Modified: code/trunk/testdata/testoutput5
===================================================================
--- code/trunk/testdata/testoutput5    2015-10-30 17:17:40 UTC (rev 399)
+++ code/trunk/testdata/testoutput5    2015-10-30 17:30:03 UTC (rev 400)
@@ -4060,4 +4060,8 @@
         End
 ------------------------------------------------------------------


+/abc/utf,replace=xyz
+    abc\=zero_terminate
+ 1: xyz
+
 # End of testinput5