bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: memmem issues


From: Paul Eggert
Subject: Re: memmem issues
Date: Sat, 29 Dec 2007 01:19:16 -0800
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux)

Bruno Haible <address@hidden> writes:

> Most of your comments apply to all copies of the KMP code in gnulib.

Ouch!  Should these be coalesced?

>> Shouldn't this check for overflow in the multiplication?
>
> Yes, it should. I'm always lazy about this.

OK, I installed this patch.

2007-12-29  Paul Eggert  <address@hidden>

        * lib/memmem.c (knuth_morris_pratt): Check for size_t overflow
        when multiplying M by sizeof (size_t).

diff --git a/lib/memmem.c b/lib/memmem.c
index 58f95f7..b7f3e12 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.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]