[Top][All Lists]
[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.
- memmem issues, Eric Blake, 2007/12/19
- Re: memmem issues, Jim Meyering, 2007/12/20
- Re: memmem issues, Jim Meyering, 2007/12/20
- Re: memmem issues, Simon Josefsson, 2007/12/20
- Re: memmem issues, Paul Eggert, 2007/12/21
- Re: memmem issues, Paul Eggert, 2007/12/29
- Re: memmem issues, Bruno Haible, 2007/12/31
- Re: memmem issues, Paul Eggert, 2007/12/31
Re: memmem issues, Bruno Haible, 2007/12/26
Re: memmem issues, Bruno Haible, 2007/12/26