summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15>2018-09-02 17:05:38 +0000
committerph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15>2018-09-02 17:05:38 +0000
commit7abc4de8303e8908eeb96714dac53ae10ff465e3 (patch)
treee2bb8ba18da4e0ea9619302e23d68b8e350dff74
parent952cac5f4a17e52aec7d0536f405b25428367840 (diff)
downloadpcre-7abc4de8303e8908eeb96714dac53ae10ff465e3.tar.gz
Fix anchoring bug in conditional subexpression.
git-svn-id: svn://vcs.exim.org/pcre/code/trunk@1739 2f5784b3-3f2a-0410-8824-cb99058d5e15
-rw-r--r--ChangeLog5
-rw-r--r--pcre_compile.c12
-rw-r--r--testdata/testinput23
-rw-r--r--testdata/testoutput24
4 files changed, 22 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index ac42247..8eed174 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -32,6 +32,11 @@ negative class with no characters less than 0x100 followed by a positive class
with only characters less than 0x100, the first class was incorrectly being
auto-possessified, causing incorrect match failures.
+6. If the only branch in a conditional subpattern was anchored, the whole
+subpattern was treated as anchored, when it should not have been, since the
+assumed empty second branch cannot be anchored. Demonstrated by test patterns
+such as /(?(1)^())b/ or /(?(?=^))b/.
+
Version 8.42 20-March-2018
--------------------------
diff --git a/pcre_compile.c b/pcre_compile.c
index 3991d6c..6141fb3 100644
--- a/pcre_compile.c
+++ b/pcre_compile.c
@@ -8682,10 +8682,18 @@ do {
if (!is_anchored(scode, new_map, cd, atomcount)) return FALSE;
}
- /* Positive forward assertions and conditions */
+ /* Positive forward assertion */
- else if (op == OP_ASSERT || op == OP_COND)
+ else if (op == OP_ASSERT)
+ {
+ if (!is_anchored(scode, bracket_map, cd, atomcount)) return FALSE;
+ }
+
+ /* Condition; not anchored if no second branch */
+
+ else if (op == OP_COND)
{
+ if (scode[GET(scode,1)] != OP_ALT) return FALSE;
if (!is_anchored(scode, bracket_map, cd, atomcount)) return FALSE;
}
diff --git a/testdata/testinput2 b/testdata/testinput2
index 8ba4dc4..3528de1 100644
--- a/testdata/testinput2
+++ b/testdata/testinput2
@@ -4257,4 +4257,7 @@ backtracking verbs. --/
ab
aaab
+/(?(?=^))b/
+ abc
+
/-- End of testinput2 --/
diff --git a/testdata/testoutput2 b/testdata/testoutput2
index 61ed8d9..4ccda27 100644
--- a/testdata/testoutput2
+++ b/testdata/testoutput2
@@ -14721,4 +14721,8 @@ No need char
0: ab
1: a
+/(?(?=^))b/
+ abc
+ 0: b
+
/-- End of testinput2 --/