From: Paul Eggert <eggert@cs.ucla.edu>
Date: Sat, 29 Dec 2007 09:17:08 +0000 (-0800)
Subject: * lib/memmem.c (knuth_morris_pratt): Check for size_t overflow
X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f1c88d2ef7d0860d2374e325d0b26febc11479b7;p=pspp

* lib/memmem.c (knuth_morris_pratt): Check for size_t overflow

when multiplying M by sizeof (size_t).
---

diff --git a/ChangeLog b/ChangeLog
index 364a429f2f..ada100e7e2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2007-12-29  Paul Eggert  <eggert@cs.ucla.edu>
+
+	* lib/memmem.c (knuth_morris_pratt): Check for size_t overflow
+	when multiplying M by sizeof (size_t).
+
 2007-12-10  Martin Lambers <marlam@marlam.de>
 
 	Override getpagesize on mingw.
diff --git a/lib/memmem.c b/lib/memmem.c
index 58f95f73b1..b7f3e12c6c 100644
--- a/lib/memmem.c
+++ b/lib/memmem.c
@@ -39,7 +39,10 @@ knuth_morris_pratt (const char *haystack, const char *last_haystack,
                     const char **resultp)
 {
   /* Allocate the table.  */
-  size_t *table = (size_t *) malloca (m * sizeof (size_t));
+  size_t *table;
+  if ((size_t) -1 / sizeof (size_t) < m)
+    return false;
+  table = (size_t *) malloca (m * sizeof (size_t));
   if (table == NULL)
     return false;
   /* Fill the table.