]> Savannah Git Hosting - gnulib.git/commitdiff
regex: fix undefined behavior
authorEgor Ignatov <egori@altlinux.org>
Tue, 22 Jun 2021 19:35:15 +0000 (12:35 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 22 Jun 2021 19:40:33 +0000 (12:40 -0700)
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  <egori@altlinux.org>  (tiny change)

ChangeLog
lib/regexec.c

index bf51718de842f7a0776633c7433028f0b144e457..6b7fd92c3965c831dfa50766217b81120cbdb049 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2021-06-22  Egor Ignatov  <egori@altlinux.org>  (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  <eblake@redhat.com>
 
        sigsegv, sigsegv-tests: Assign my contributions to the FSF.
        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  <egori@altlinux.org>
+2021-06-06  Egor Ignatov  <egori@altlinux.org>  (tiny change)
 
        * lib/regexec.c (set_regs): Pop if CUR_NODE has already been checked
        only when we have a fail stack.
index 5d4113c9d3eea73f0dedf6007db5e21443c63851..5e4eb497a6bb166e225d33f3e730426d0ad1526e 100644 (file)
@@ -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;