regex: don't infloop on persistent failing calloc
authorJim Meyering <meyering@redhat.com>
Tue, 28 Dec 2010 14:12:47 +0000 (15:12 +0100)
committerJim Meyering <meyering@redhat.com>
Tue, 28 Dec 2010 14:16:28 +0000 (15:16 +0100)
* lib/regexec.c (build_trtable): Return failure indication upon
calloc failure.  Otherwise, re_search_internal could infloop on OOM.
In glibc, this was fixed for version 2.13:
http://sourceware.org/bugzilla/show_bug.cgi?id=12348

ChangeLog
lib/regexec.c

index 0d175a2..0a17782 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2010-12-28  Jim Meyering  <meyering@redhat.com>
+
+       regex: don't infloop on persistent failing calloc
+       * lib/regexec.c (build_trtable): Return failure indication upon
+       calloc failure.  Otherwise, re_search_internal could infloop on OOM.
+       In glibc, this was fixed for version 2.13:
+       http://sourceware.org/bugzilla/show_bug.cgi?id=12348
+
 2010-12-28  Bruno Haible  <bruno@clisp.org>
             Paul Eggert <eggert@cs.ucla.edu>
 
index 9388ac1..ee702bc 100644 (file)
@@ -3402,6 +3402,8 @@ build_trtable (const re_dfa_t *dfa, re_dfastate_t *state)
        {
          state->trtable = (re_dfastate_t **)
            calloc (sizeof (re_dfastate_t *), SBC_MAX);
+          if (BE (state->trtable == NULL, 0))
+            return false;
          return true;
        }
       return false;