bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 2/2] Diagnose ERE '()|\1'


From: Paul Eggert
Subject: [PATCH 2/2] Diagnose ERE '()|\1'
Date: Sat, 19 Sep 2015 13:55:12 -0700

Problem reported by Hanno Böck in: http://bugs.gnu.org/21513
* lib/regcomp.c (parse_reg_exp): While parsing alternatives, keep
track of the set of previously-completed subexpressions available
before the first alternative, and restore this set just before
parsing each subsequent alternative.  This lets us diagnose the
invalid back-reference in the ERE '()|\1'.
---
 ChangeLog     | 8 ++++++++
 lib/regcomp.c | 4 ++++
 2 files changed, 12 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index f846aac..7c83566 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2015-09-19  Paul Eggert  <address@hidden>
 
+       Diagnose ERE '()|\1'
+       Problem reported by Hanno Böck in: http://bugs.gnu.org/21513
+       * lib/regcomp.c (parse_reg_exp): While parsing alternatives, keep
+       track of the set of previously-completed subexpressions available
+       before the first alternative, and restore this set just before
+       parsing each subsequent alternative.  This lets us diagnose the
+       invalid back-reference in the ERE '()|\1'.
+
        regex: merge patches from libc
 
        2015-09-08  Joseph Myers  <address@hidden>
diff --git a/lib/regcomp.c b/lib/regcomp.c
index f50afb4..4cbb1b2 100644
--- a/lib/regcomp.c
+++ b/lib/regcomp.c
@@ -2191,6 +2191,7 @@ parse_reg_exp (re_string_t *regexp, regex_t *preg, 
re_token_t *token,
 {
   re_dfa_t *dfa = preg->buffer;
   bin_tree_t *tree, *branch = NULL;
+  bitset_word_t initial_bkref_map = dfa->completed_bkref_map;
   tree = parse_branch (regexp, preg, token, syntax, nest, err);
   if (BE (*err != REG_NOERROR && tree == NULL, 0))
     return NULL;
@@ -2201,6 +2202,8 @@ parse_reg_exp (re_string_t *regexp, regex_t *preg, 
re_token_t *token,
       if (token->type != OP_ALT && token->type != END_OF_RE
          && (nest == 0 || token->type != OP_CLOSE_SUBEXP))
        {
+         bitset_word_t accumulated_bkref_map = dfa->completed_bkref_map;
+         dfa->completed_bkref_map = initial_bkref_map;
          branch = parse_branch (regexp, preg, token, syntax, nest, err);
          if (BE (*err != REG_NOERROR && branch == NULL, 0))
            {
@@ -2208,6 +2211,7 @@ parse_reg_exp (re_string_t *regexp, regex_t *preg, 
re_token_t *token,
                postorder (tree, free_tree, NULL);
              return NULL;
            }
+         dfa->completed_bkref_map |= accumulated_bkref_map;
        }
       else
        branch = NULL;
-- 
2.1.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]