From 7e3a9c5bde817dab5b9a6987a373e6a3c2e6576b Mon Sep 17 00:00:00 2001 From: Egor Ignatov Date: Tue, 22 Jun 2021 12:35:15 -0700 Subject: [PATCH] regex: fix undefined behavior MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Problem reported by Paul Eggert in: https://lists.gnu.org/r/bug-gnulib/2021-06/msg00115.html * lib/regexec.c (proceed_next_node): Don’t insert already-inserted node. 2021-06-06 Egor Ignatov (tiny change) --- ChangeLog | 10 +++++++++- lib/regexec.c | 10 +++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index bf51718de8..6b7fd92c39 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2021-06-22 Egor Ignatov (tiny change) + + regex: fix undefined behavior + Problem reported by Paul Eggert in: + https://lists.gnu.org/r/bug-gnulib/2021-06/msg00115.html + * lib/regexec.c (proceed_next_node): + Don’t insert already-inserted node. + 2021-06-21 Eric Blake sigsegv, sigsegv-tests: Assign my contributions to the FSF. @@ -324,7 +332,7 @@ are not used. That comment was copied along with tests from glibc where some of these tests are commented out. -2021-06-06 Egor Ignatov +2021-06-06 Egor Ignatov (tiny change) * lib/regexec.c (set_regs): Pop if CUR_NODE has already been checked only when we have a fail stack. diff --git a/lib/regexec.c b/lib/regexec.c index 5d4113c9d3..5e4eb497a6 100644 --- a/lib/regexec.c +++ b/lib/regexec.c @@ -1220,9 +1220,13 @@ proceed_next_node (const re_match_context_t *mctx, Idx nregs, regmatch_t *regs, { re_node_set *cur_nodes = &mctx->state_log[*pidx]->nodes; re_node_set *edests = &dfa->edests[node]; - bool ok = re_node_set_insert (eps_via_nodes, node); - if (__glibc_unlikely (! ok)) - return -2; + + if (! re_node_set_contains (eps_via_nodes, node)) + { + bool ok = re_node_set_insert (eps_via_nodes, node); + if (__glibc_unlikely (! ok)) + return -2; + } /* Pick a valid destination, or return -1 if none is found. */ Idx dest_node = -1; -- 2.39.5