From: Egor Ignatov Date: Tue, 22 Jun 2021 19:35:15 +0000 (-0700) Subject: regex: fix undefined behavior X-Git-Tag: v1.0~2794 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=7e3a9c5bde817dab5b9a6987a373e6a3c2e6576b;p=gnulib.git 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-06 Egor Ignatov (tiny change) --- 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;