summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15>2009-12-11 16:42:50 +0000
committerph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15>2009-12-11 16:42:50 +0000
commitd70bdebcc62f48ae54bb2d7e7216d629bdc5dfcc (patch)
tree9c0d659870e3e500a4422901d1bb559e9d4fd7f2
parentb84f61cc8c29b9d3c36794906770fe8b22bf2e0c (diff)
downloadpcre-d70bdebcc62f48ae54bb2d7e7216d629bdc5dfcc.tar.gz
Fix options set and reset at top level bug.
git-svn-id: svn://vcs.exim.org/pcre/code/trunk@472 2f5784b3-3f2a-0410-8824-cb99058d5e15
-rw-r--r--ChangeLog7
-rw-r--r--pcre_compile.c14
-rw-r--r--testdata/testinput17
-rw-r--r--testdata/testinput211
-rw-r--r--testdata/testoutput112
-rw-r--r--testdata/testoutput249
6 files changed, 98 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 749a674..d7adfca 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -8,6 +8,13 @@ Version 8.01 11-Dec-09
particular, this includes all (DEFINE) patterns), a call to pcre_study()
computed the wrong minimum data length (which is of course zero for such
subpatterns).
+
+2. For patterns such as (?i)a(?-i)b|c where an option setting at the start of
+ the pattern is reset in the first branch, pcre_compile() failed with
+ "internal error: code overflow at offset...". This happened only when
+ the reset was to the original external option setting. (An optimization
+ abstracts leading options settings into an external setting, which was the
+ cause of this.)
Version 8.00 19-Oct-09
diff --git a/pcre_compile.c b/pcre_compile.c
index c360c43..0605a6e 100644
--- a/pcre_compile.c
+++ b/pcre_compile.c
@@ -5248,7 +5248,7 @@ we set the flag only if there is a literal "\r" or "\n" in the class. */
{
cd->external_options = newoptions;
}
- else
+ else
{
if ((options & PCRE_IMS) != (newoptions & PCRE_IMS))
{
@@ -5783,6 +5783,7 @@ int branchfirstbyte, branchreqbyte;
int length;
int orig_bracount;
int max_bracount;
+int old_external_options = cd->external_options;
branch_chain bc;
bc.outer = bcptr;
@@ -5859,6 +5860,15 @@ for (;;)
return FALSE;
}
+ /* If the external options have changed during this branch, it means that we
+ are at the top level, and a leading option setting has been encountered. We
+ need to re-set the original option values to take account of this so that,
+ during the pre-compile phase, we know to allow for a re-set at the start of
+ subsequent branches. */
+
+ if (old_external_options != cd->external_options)
+ oldims = cd->external_options & PCRE_IMS;
+
/* Keep the highest bracket count in case (?| was used and some branch
has fewer than the rest. */
@@ -5969,7 +5979,7 @@ for (;;)
PUT(code, 1, code - start_bracket);
code += 1 + LINK_SIZE;
- /* Resetting option if needed */
+ /* Reset options if needed. */
if ((options & PCRE_IMS) != oldims && *ptr == CHAR_RIGHT_PARENTHESIS)
{
diff --git a/testdata/testinput1 b/testdata/testinput1
index 6cacbb5..48cc5a9 100644
--- a/testdata/testinput1
+++ b/testdata/testinput1
@@ -4067,4 +4067,11 @@
/^%((?(?=[a])[^%])|b)*%$/
%ab%
+/(?i)a(?-i)b|c/
+ XabX
+ XAbX
+ CcC
+ ** Failers
+ XABX
+
/-- End of testinput1 --/
diff --git a/testdata/testinput2 b/testdata/testinput2
index c49b94f..8e1a5e8 100644
--- a/testdata/testinput2
+++ b/testdata/testinput2
@@ -3175,4 +3175,15 @@ a random value. /Ix
/()i(?(1)a)/SI
ia
+/(?i)a(?-i)b|c/BZ
+ XabX
+ XAbX
+ CcC
+ ** Failers
+ XABX
+
+/(?i)a(?s)b|c/BZ
+
+/(?i)a(?s-i)b|c/BZ
+
/-- End of testinput2 --/
diff --git a/testdata/testoutput1 b/testdata/testoutput1
index a2a6dd4..6c28602 100644
--- a/testdata/testoutput1
+++ b/testdata/testoutput1
@@ -6649,4 +6649,16 @@ No match
0: %ab%
1:
+/(?i)a(?-i)b|c/
+ XabX
+ 0: ab
+ XAbX
+ 0: Ab
+ CcC
+ 0: c
+ ** Failers
+No match
+ XABX
+No match
+
/-- End of testinput1 --/
diff --git a/testdata/testoutput2 b/testdata/testoutput2
index be968da..83aef94 100644
--- a/testdata/testoutput2
+++ b/testdata/testoutput2
@@ -10486,4 +10486,53 @@ Starting byte set: i
0: ia
1:
+/(?i)a(?-i)b|c/BZ
+------------------------------------------------------------------
+ Bra
+ NC a
+ 00 Opt
+ b
+ Alt
+ 00 Opt
+ c
+ Ket
+ End
+------------------------------------------------------------------
+ XabX
+ 0: ab
+ XAbX
+ 0: Ab
+ CcC
+ 0: c
+ ** Failers
+No match
+ XABX
+No match
+
+/(?i)a(?s)b|c/BZ
+------------------------------------------------------------------
+ Bra
+ NC a
+ 05 Opt
+ NC b
+ Alt
+ 05 Opt
+ NC c
+ Ket
+ End
+------------------------------------------------------------------
+
+/(?i)a(?s-i)b|c/BZ
+------------------------------------------------------------------
+ Bra
+ NC a
+ 04 Opt
+ b
+ Alt
+ 04 Opt
+ c
+ Ket
+ End
+------------------------------------------------------------------
+
/-- End of testinput2 --/