This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[RFA] libiberty/hashtab.c, higher_prime_index: avoid array overrun
- From: Michael Snyder <msnyder at vmware dot com>
- To: "dj at redhat dot com" <dj at redhat dot com>, "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>, "gdb-patches at sourceware dot org" <gdb-patches at sourceware dot org>
- Date: Thu, 03 Mar 2011 14:04:06 -0800
- Subject: [RFA] libiberty/hashtab.c, higher_prime_index: avoid array overrun
As written, the function will access element [30] of a 30-element array.
OK?
2011-03-03 Michael Snyder <msnyder@vmware.com>
* hashtab.c (higher_prime_index): Prevent array overrun.
Index: hashtab.c
===================================================================
RCS file: /cvs/src/src/libiberty/hashtab.c,v
retrieving revision 1.38
diff -u -p -u -p -r1.38 hashtab.c
--- hashtab.c 3 Feb 2011 07:23:59 -0000 1.38
+++ hashtab.c 3 Mar 2011 22:01:08 -0000
@@ -173,9 +173,9 @@ static unsigned int
higher_prime_index (unsigned long n)
{
unsigned int low = 0;
- unsigned int high = sizeof(prime_tab) / sizeof(prime_tab[0]);
+ unsigned int high = sizeof(prime_tab) / sizeof(prime_tab[0]) - 1;
- while (low != high)
+ while (low < high)
{
unsigned int mid = low + (high - low) / 2;
if (n > prime_tab[mid].prime)