[CVE-2009-5155] Diagnose ERE '()|\1' 95/286695/1 accepted/tizen_6.0_base accepted/tizen_6.0_base_tool tizen_6.0_base accepted/tizen/6.0/base/20230713.143134 accepted/tizen/6.0/base/tool/20230116.011832 submit/tizen_6.0_base/20230112.235320
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 19 Sep 2015 20:53:34 +0000 (13:53 -0700)
committerDongHun Kwak <dh0128.kwak@samsung.com>
Thu, 12 Jan 2023 00:34:15 +0000 (09:34 +0900)
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'.

Change-Id: Id55c5afc1cc560444e82bdef4ce5462d2f3f6f3a
Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
gnulib/lib/regcomp.c

index fe4d243..ab0628f 100644 (file)
@@ -2116,6 +2116,7 @@ parse_reg_exp (re_string_t *regexp, regex_t *preg, re_token_t *token,
 {
   re_dfa_t *dfa = (re_dfa_t *) 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;
@@ -2126,9 +2127,12 @@ 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))
            return NULL;
+         dfa->completed_bkref_map |= accumulated_bkref_map;
        }
       else
        branch = NULL;