diff options
author | ph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15> | 2007-06-04 11:21:13 +0000 |
---|---|---|
committer | ph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15> | 2007-06-04 11:21:13 +0000 |
commit | 977a33e0e05ab3378b480a7270a0d89c24644dec (patch) | |
tree | 08a0b19d126126d46fc666fbc75aaefd60729d56 | |
parent | 756fe1f5dfc297c4420809b85f636f7fdcfce7ff (diff) | |
download | pcre-977a33e0e05ab3378b480a7270a0d89c24644dec.tar.gz |
Fix bug in detecting potentially empty groups.
git-svn-id: svn://vcs.exim.org/pcre/code/trunk@170 2f5784b3-3f2a-0410-8824-cb99058d5e15
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | pcre_compile.c | 18 | ||||
-rw-r--r-- | testdata/testinput1 | 3 | ||||
-rw-r--r-- | testdata/testoutput1 | 5 |
4 files changed, 24 insertions, 6 deletions
@@ -38,6 +38,10 @@ Version 7.2 01-May-07 7. Added two new calls to pcre_fullinfo(): PCRE_INFO_OKPARTIAL and PCRE_INFO_JCHANGED. + + 8. A pattern such as (.*(.)?)* caused pcre_exec() to fail by either not + terminating or by crashing. Diagnosed by Viktor Griph; it was in the code + for detecting groups that can match an empty string. Version 7.1 24-Apr-07 diff --git a/pcre_compile.c b/pcre_compile.c index 2002d20..c930193 100644 --- a/pcre_compile.c +++ b/pcre_compile.c @@ -1370,7 +1370,18 @@ for (code = first_significant_code(code + _pcre_OP_lengths[*code], NULL, 0, TRUE const uschar *ccode; c = *code; + + /* Groups with zero repeats can of course be empty; skip them. */ + if (c == OP_BRAZERO || c == OP_BRAMINZERO) + { + do code += GET(code, 1); while (*code == OP_ALT); + c = *code; + continue; + } + + /* For other groups, scan the branches. */ + if (c == OP_BRA || c == OP_CBRA || c == OP_ONCE) { BOOL empty_branch; @@ -1387,12 +1398,7 @@ for (code = first_significant_code(code + _pcre_OP_lengths[*code], NULL, 0, TRUE } while (*code == OP_ALT); if (!empty_branch) return FALSE; /* All branches are non-empty */ - - /* Move past the KET and fudge things so that the increment in the "for" - above has no effect. */ - - c = OP_END; - code += 1 + LINK_SIZE - _pcre_OP_lengths[c]; + c = *code; continue; } diff --git a/testdata/testinput1 b/testdata/testinput1 index d8ef12b..4d619a8 100644 --- a/testdata/testinput1 +++ b/testdata/testinput1 @@ -4018,4 +4018,7 @@ abc abc\n +/(.*(.)?)*/ + abcd + / End of testinput1 / diff --git a/testdata/testoutput1 b/testdata/testoutput1 index b513dca..0bfad1e 100644 --- a/testdata/testoutput1 +++ b/testdata/testoutput1 @@ -6571,4 +6571,9 @@ No match abc\n No match +/(.*(.)?)*/ + abcd + 0: abcd + 1: + / End of testinput1 / |