[CVE-2009-5155] Diagnose ERE '()|\1' 88/253588/2 accepted/tizen_6.5_base accepted/tizen_6.5_base_tool accepted/tizen_7.0_base accepted/tizen_7.0_base_hotfix accepted/tizen_7.0_base_tool accepted/tizen_7.0_base_tool_hotfix sandbox/backup/diffutils_3.3_20221227 tizen_6.5_base tizen_7.0_base tizen_7.0_base_hotfix accepted/tizen/6.5/base/20230714.002446 accepted/tizen/6.5/base/tool/20211027.112245 accepted/tizen/7.0/base/20230714.002855 accepted/tizen/7.0/base/hotfix/20230714.003710 accepted/tizen/7.0/base/tool/20221028.113107 accepted/tizen/7.0/base/tool/hotfix/20221115.084857 accepted/tizen/base/tool/20210221.221005 submit/sandbox/backup/diffutils_3.3_20221227/20230105.055728 submit/tizen_6.5_base/20211026.180901 submit/tizen_6.5_base/20211027.183101 submit/tizen_6.5_base/20211027.200501 submit/tizen_7.0_base/20221028.200901 submit/tizen_7.0_base_hotfix/20221115.161501 submit/tizen_base/20210216.020958 tizen_6.5.m2_release tizen_7.0_m2_release
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 19 Sep 2015 20:53:34 +0000 (13:53 -0700)
committerDongHun Kwak <dh0128.kwak@samsung.com>
Tue, 16 Feb 2021 01:46:48 +0000 (10:46 +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: I33d1ba3c5c4e3460b81cda46eac2a4eac625b8c3
Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
lib/regcomp.c

index f7cfebe..63f08c1 100644 (file)
@@ -2182,6 +2182,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;
@@ -2192,9 +2193,16 @@ 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;
+           {
+             if (tree != NULL)
+               postorder (tree, free_tree, NULL);
+             return NULL;
+           }
+         dfa->completed_bkref_map |= accumulated_bkref_map;
        }
       else
        branch = NULL;