]> Savannah Git Hosting - gnulib.git/commitdiff
regex: don't deref NULL upon heap allocation failure
authorJim Meyering <meyering@fb.com>
Sat, 12 Jul 2014 23:33:49 +0000 (16:33 -0700)
committerJim Meyering <meyering@fb.com>
Sat, 12 Jul 2014 23:44:12 +0000 (16:44 -0700)
* lib/regcomp.c (parse_dup_op): Handle duplicate_tree
failure in one more place.
To trigger the segfault, configure grep -with-included-regex,
build it, and run these commands:
( ulimit -v 300000; echo a|src/grep -E a+++++++++++++++++++++ )
I discovered this while replying to a private report from
Jens Schleusener about excessive memory consumption by grep
when using a regular expression like the one above.

ChangeLog
lib/regcomp.c

index 0a7b82f958c320870a74238ee1a87b14f9ddff42..8131fd105e67a8f9aa417eaad22ae843d14d0178 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2014-07-12  Jim Meyering  <meyering@fb.com>
+
+       regex: don't deref NULL upon heap allocation failure
+       * lib/regcomp.c (parse_dup_op): Handle duplicate_tree
+       failure in one more place.
+       To trigger the segfault, configure grep -with-included-regex,
+       build it, and run these commands:
+       ( ulimit -v 300000; echo a|src/grep -E a+++++++++++++++++++++ )
+       I discovered this while replying to a private report from
+       Jens Schleusener about excessive memory consumption by grep
+       when using a regular expression like the one above.
+
 2014-07-11  Paul Eggert  <eggert@cs.ucla.edu>
 
        regex: fix memory leak in compiler
index 44c6c5ebb2c19254bdabed4138ea49e13bcb27f0..c306ffb7e77dc496da83c2824a73ed5cfefded18 100644 (file)
@@ -2635,6 +2635,8 @@ parse_dup_op (bin_tree_t *elem, re_string_t *regexp, re_dfa_t *dfa,
 
       /* Duplicate ELEM before it is marked optional.  */
       elem = duplicate_tree (elem, dfa);
+      if (BE (elem == NULL, 0))
+        goto parse_dup_op_espace;
       old_tree = tree;
     }
   else