Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Michael Snyder <msnyder@vmware.com>
To: "dj@redhat.com" <dj@redhat.com>,
	 "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>,
	"gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: [RFA] libiberty/hashtab.c, higher_prime_index: avoid array overrun
Date: Thu, 03 Mar 2011 22:04:00 -0000	[thread overview]
Message-ID: <4D701056.1080208@vmware.com> (raw)

[-- 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)

             reply	other threads:[~2011-03-03 22:04 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-03 22:04 Michael Snyder [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4D701056.1080208@vmware.com \
    --to=msnyder@vmware.com \
    --cc=dj@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox