* lib/memmem.c (knuth_morris_pratt): Check for size_t overflow
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 29 Dec 2007 09:17:08 +0000 (01:17 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 29 Dec 2007 09:17:08 +0000 (01:17 -0800)
when multiplying M by sizeof (size_t).

ChangeLog
lib/memmem.c

index 364a429..ada100e 100644 (file)
--- 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.
index 58f95f7..b7f3e12 100644 (file)
@@ -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.