[Pcre-svn] [1625] code/trunk: Fix pcretest bad behaviour for…

Top Page
Delete this message
Author: Subversion repository
Date:  
To: pcre-svn
Subject: [Pcre-svn] [1625] code/trunk: Fix pcretest bad behaviour for callout in lookbehind.
Revision: 1625
          http://vcs.pcre.org/viewvc?view=rev&revision=1625
Author:   ph10
Date:     2016-02-06 16:54:14 +0000 (Sat, 06 Feb 2016)
Log Message:
-----------
Fix pcretest bad behaviour for callout in lookbehind.


Modified Paths:
--------------
    code/trunk/ChangeLog
    code/trunk/pcretest.c
    code/trunk/testdata/testinput2
    code/trunk/testdata/testoutput2


Modified: code/trunk/ChangeLog
===================================================================
--- code/trunk/ChangeLog    2016-02-05 13:47:43 UTC (rev 1624)
+++ code/trunk/ChangeLog    2016-02-06 16:54:14 UTC (rev 1625)
@@ -49,7 +49,11 @@


12. Assertion code generator in JIT has been optimized.

+13. A pattern such as /(?<=((?C)0))/, which has a callout inside a lookbehind
+    assertion, caused pcre2test to generate incorrect output, and also to read 
+    uninitialized memory (detected by ASAN or valgrind).


+
Version 8.38 23-November-2015
-----------------------------


Modified: code/trunk/pcretest.c
===================================================================
--- code/trunk/pcretest.c    2016-02-05 13:47:43 UTC (rev 1624)
+++ code/trunk/pcretest.c    2016-02-06 16:54:14 UTC (rev 1625)
@@ -2250,7 +2250,7 @@
 static int callout(pcre_callout_block *cb)
 {
 FILE *f = (first_callout | callout_extra)? outfile : NULL;
-int i, pre_start, post_start, subject_length;
+int i, current_position, pre_start, post_start, subject_length;


if (callout_extra)
{
@@ -2280,14 +2280,19 @@

if (f != NULL) fprintf(f, "--->");

+/* If a lookbehind is involved, the current position may be earlier than the
+match start. If so, use the match start instead. */
+
+current_position = (cb->current_position >= cb->start_match)?
+ cb->current_position : cb->start_match;
+
PCHARS(pre_start, cb->subject, 0, cb->start_match, f);
PCHARS(post_start, cb->subject, cb->start_match,
- cb->current_position - cb->start_match, f);
+ current_position - cb->start_match, f);

PCHARS(subject_length, cb->subject, 0, cb->subject_length, NULL);

-PCHARSV(cb->subject, cb->current_position,
- cb->subject_length - cb->current_position, f);
+PCHARSV(cb->subject, current_position, cb->subject_length - current_position, f);

if (f != NULL) fprintf(f, "\n");

@@ -5740,3 +5745,4 @@
}

/* End of pcretest.c */
+

Modified: code/trunk/testdata/testinput2
===================================================================
--- code/trunk/testdata/testinput2    2016-02-05 13:47:43 UTC (rev 1624)
+++ code/trunk/testdata/testinput2    2016-02-06 16:54:14 UTC (rev 1625)
@@ -4235,4 +4235,8 @@
 /(?=a\K)/ 
     ring bpattingbobnd $ 1,oern cou \rb\L


+/(?<=((?C)0))/
+    9010
+    abcd
+     
 /-- End of testinput2 --/


Modified: code/trunk/testdata/testoutput2
===================================================================
--- code/trunk/testdata/testoutput2    2016-02-05 13:47:43 UTC (rev 1624)
+++ code/trunk/testdata/testoutput2    2016-02-06 16:54:14 UTC (rev 1625)
@@ -14650,4 +14650,19 @@
  0: a
  0L 


+/(?<=((?C)0))/
+    9010
+--->9010
+  0  ^       0
+  0   ^      0
+ 0: 
+ 1: 0
+    abcd
+--->abcd
+  0  ^       0
+  0   ^      0
+  0    ^     0
+  0     ^    0
+No match
+     
 /-- End of testinput2 --/