diff lib/regcomp.c @ 17725:d65323023063

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.
author Jim Meyering <meyering@fb.com>
date Sat, 12 Jul 2014 16:33:49 -0700
parents 9edabe80a556
children ab58d4870664
line wrap: on
line diff
--- a/lib/regcomp.c	Sat Jul 12 15:21:12 2014 +0100
+++ b/lib/regcomp.c	Sat Jul 12 16:33:49 2014 -0700
@@ -2635,6 +2635,8 @@
 
       /* 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