changeset 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 8526f2f0b117
children 71758fd65b02
files ChangeLog lib/regcomp.c
diffstat 2 files changed, 14 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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
--- a/lib/regcomp.c
+++ b/lib/regcomp.c
@@ -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