Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFA] libiberty/hashtab.c, higher_prime_index: avoid array overrun
@ 2011-03-03 22:04 Michael Snyder
  2011-03-03 22:11 ` DJ Delorie
  0 siblings, 1 reply; 10+ messages in thread
From: Michael Snyder @ 2011-03-03 22:04 UTC (permalink / raw)
  To: dj, gcc-patches, gdb-patches

[-- Attachment #1: Type: text/plain, Size: 79 bytes --]

As written, the function will access element [30] of a 30-element array.

OK?


[-- Attachment #2: hashtab.txt --]
[-- Type: text/plain, Size: 764 bytes --]

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)

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2011-03-07  0:51 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-03 22:04 [RFA] libiberty/hashtab.c, higher_prime_index: avoid array overrun Michael Snyder
2011-03-03 22:11 ` DJ Delorie
2011-03-03 22:26   ` Michael Snyder
2011-03-03 22:59     ` DJ Delorie
2011-03-07  2:59       ` Michael Snyder
2011-03-03 23:01     ` Mike Stump
2011-03-03 23:24       ` Michael Snyder
2011-03-04  0:14       ` Dave Korn
2011-03-04  0:19         ` DJ Delorie
2011-03-03 22:33   ` Michael Snyder

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox