]> Savannah Git Hosting - gnulib.git/commitdiff
dfa: avoid use of uninitialized constraint
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 14 Sep 2020 01:40:08 +0000 (18:40 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 14 Sep 2020 01:41:32 +0000 (18:41 -0700)
* lib/dfa.c (merge_nfa_state): Do not initialize the constraint
to zero here.
(dfaoptimize): Do it here instead, via xcalloc.  This prevents the
use of an uninitialized constraint by later code when ! (flags[i]
& OPT_QUEUED) means merge_nfa_state was not called to initialize
the constraint.  Problem found by running 'valgrind src/grep -E
'(^| )*(a|b)*(c|d)*( |$)' < /dev/null' on Ubuntu 18.04.5 x86-64.

ChangeLog
lib/dfa.c

index 5f7a148e35f21863ce47076585a26fcf19ebd09c..395ac6bafd72e2cada0884c54f470cf91eacf8b9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2020-09-13  Paul Eggert  <eggert@cs.ucla.edu>
 
+       dfa: avoid use of uninitialized constraint
+       * lib/dfa.c (merge_nfa_state): Do not initialize the constraint
+       to zero here.
+       (dfaoptimize): Do it here instead, via xcalloc.  This prevents the
+       use of an uninitialized constraint by later code when ! (flags[i]
+       & OPT_QUEUED) means merge_nfa_state was not called to initialize
+       the constraint.  Problem found by running 'valgrind src/grep -E
+       '(^| )*(a|b)*(c|d)*( |$)' < /dev/null' on Ubuntu 18.04.5 x86-64.
+
        dfa: assume C99 in reorder_tokens
        * lib/dfa.c (reorder_tokens): Assume C99 and simplify.
 
index 0fa9958fdc3fc85b1ac0a83f3bee4958f6d4cd14..746c7b56811c842b12dbd9602dafc8b1b63c7dd7 100644 (file)
--- a/lib/dfa.c
+++ b/lib/dfa.c
@@ -2428,8 +2428,6 @@ merge_nfa_state (struct dfa *d, idx_t tindex, char *flags,
   position_set *follows = d->follows;
   idx_t nelem = 0;
 
-  d->constraints[tindex] = 0;
-
   for (idx_t i = 0; i < follows[tindex].nelem; i++)
     {
       idx_t sindex = follows[tindex].elems[i].index;
@@ -2581,7 +2579,7 @@ dfaoptimize (struct dfa *d)
   position_set *merged = &merged0;
   alloc_position_set (merged, d->nleaves);
 
-  d->constraints = xnmalloc (d->tindex, sizeof *d->constraints);
+  d->constraints = xcalloc (d->tindex, sizeof *d->constraints);
 
   for (idx_t i = 0; i < d->tindex; i++)
     if (flags[i] & OPT_QUEUED)