Revision: 314
http://www.exim.org/viewvc/pcre2?view=rev&revision=314
Author: ph10
Date: 2015-07-17 16:11:45 +0100 (Fri, 17 Jul 2015)
Log Message:
-----------
Fix bad compilation of a possessively repeated conditional that could match an
empty string.
Modified Paths:
--------------
code/trunk/ChangeLog
code/trunk/src/pcre2_compile.c
code/trunk/testdata/testinput2
code/trunk/testdata/testoutput2
Modified: code/trunk/ChangeLog
===================================================================
--- code/trunk/ChangeLog 2015-07-17 14:22:04 UTC (rev 313)
+++ code/trunk/ChangeLog 2015-07-17 15:11:45 UTC (rev 314)
@@ -40,7 +40,10 @@
10. The quantifier {1} can be ignored, whether greedy, non-greedy, or
possessive. This is a very minor optimization.
+11. A possessively repeated conditional group that could match an empty string,
+for example, /(?(R))*+/, was incorrectly compiled.
+
Version 10.20 30-June-2015
--------------------------
Modified: code/trunk/src/pcre2_compile.c
===================================================================
--- code/trunk/src/pcre2_compile.c 2015-07-17 14:22:04 UTC (rev 313)
+++ code/trunk/src/pcre2_compile.c 2015-07-17 15:11:45 UTC (rev 314)
@@ -5269,7 +5269,7 @@
conditional, we convert the BRA code to the POS form, and the KET code to
KETRPOS. (It turns out to be convenient at runtime to detect this kind of
subpattern at both the start and at the end.) The use of special opcodes
- makes it possible to reduce greatly the stack usage in pcre_exec(). If
+ makes it possible to reduce greatly the stack usage in pcre2_match(). If
the group is preceded by OP_BRAZERO, convert this to OP_BRAPOSZERO.
Then, if the minimum number of matches is 1 or 0, cancel the possessive
@@ -5333,7 +5333,7 @@
memmove(bracode + 1 + LINK_SIZE, bracode, CU2BYTES(nlen));
code += 1 + LINK_SIZE;
nlen += 1 + LINK_SIZE;
- *bracode = OP_BRAPOS;
+ *bracode = (*bracode == OP_COND)? OP_BRAPOS : OP_SBRAPOS;
*code++ = OP_KETRPOS;
PUTINC(code, 0, nlen);
PUT(bracode, 1, nlen);
Modified: code/trunk/testdata/testinput2
===================================================================
--- code/trunk/testdata/testinput2 2015-07-17 14:22:04 UTC (rev 313)
+++ code/trunk/testdata/testinput2 2015-07-17 15:11:45 UTC (rev 314)
@@ -4339,4 +4339,6 @@
/(?C$)$)(?<]/
+/(?(R))*+/B
+
# End of testinput2
Modified: code/trunk/testdata/testoutput2
===================================================================
--- code/trunk/testdata/testoutput2 2015-07-17 14:22:04 UTC (rev 313)
+++ code/trunk/testdata/testoutput2 2015-07-17 15:11:45 UTC (rev 314)
@@ -14499,4 +14499,17 @@
/(?C$)$)(?<]/
Failed: error 124 at offset 10: unrecognized character after (?<
+/(?(R))*+/B
+------------------------------------------------------------------
+ Bra
+ Braposzero
+ SBraPos
+ SCond
+ Cond recurse any
+ Ket
+ KetRpos
+ Ket
+ End
+------------------------------------------------------------------
+
# End of testinput2