From abfc467cb9b2c51a7bcfa32c9b1926c21f2ed373 Mon Sep 17 00:00:00 2001 From: ph10 Date: Wed, 22 Jul 2015 09:33:04 +0000 Subject: Fix (?R- not being diagnosed correctly. git-svn-id: svn://vcs.exim.org/pcre/code/trunk@1582 2f5784b3-3f2a-0410-8824-cb99058d5e15 --- ChangeLog | 7 +++++-- pcre_compile.c | 21 +++++++++++++-------- testdata/testinput2 | 2 ++ testdata/testoutput2 | 3 +++ 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index e68f416..93fd247 100644 --- a/ChangeLog +++ b/ChangeLog @@ -88,13 +88,16 @@ Version 8.38 xx-xxx-xxxx compiled and could cause reading from uninitialized memory or an incorrect error diagnosis. -16. Pathological patterns containing many nested occurrences of [: caused +23. Pathological patterns containing many nested occurrences of [: caused pcre_compile() to run for a very long time. -17. A conditional group with only one branch has an implicit empty alternative +24. A conditional group with only one branch has an implicit empty alternative branch and must therefore be treated as potentially matching an empty string. +25. If (?R was followed by - or + incorrect behaviour happened instead of a + diagnostic. + Version 8.37 28-April-2015 -------------------------- diff --git a/pcre_compile.c b/pcre_compile.c index e9d1052..7d9f276 100644 --- a/pcre_compile.c +++ b/pcre_compile.c @@ -3936,7 +3936,7 @@ pcre_uchar terminator; /* Don't combine these lines; the Solaris cc */ terminator = *(++ptr); /* compiler warns about "non-constant" initializer. */ for (++ptr; *ptr != CHAR_NULL; ptr++) { - if (*ptr == CHAR_BACKSLASH && + if (*ptr == CHAR_BACKSLASH && (ptr[1] == CHAR_RIGHT_SQUARE_BRACKET || ptr[1] == CHAR_BACKSLASH)) ptr++; @@ -6274,13 +6274,13 @@ for (;; ptr++) } while (*scode == OP_ALT); } - - /* A conditional group with only one branch has an implicit empty + + /* A conditional group with only one branch has an implicit empty alternative branch. */ if (*bracode == OP_COND && bracode[GET(bracode,1)] != OP_ALT) - *bracode = OP_SCOND; - + *bracode = OP_SCOND; + /* Handle possessive quantifiers. */ if (possessive_quantifier) @@ -7337,9 +7337,14 @@ for (;; ptr++) /* ------------------------------------------------------------ */ - case CHAR_R: /* Recursion */ - ptr++; /* Same as (?0) */ - /* Fall through */ + case CHAR_R: /* Recursion, same as (?0) */ + recno = 0; + if (*(++ptr) != CHAR_RIGHT_PARENTHESIS) + { + *errorcodeptr = ERR29; + goto FAILED; + } + goto HANDLE_RECURSION; /* ------------------------------------------------------------ */ diff --git a/testdata/testinput2 b/testdata/testinput2 index d83c436..8f18fa4 100644 --- a/testdata/testinput2 +++ b/testdata/testinput2 @@ -4190,4 +4190,6 @@ backtracking verbs. --/ /()(?(R)0)*+/BZ +/(?R-:(?