qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Weil <sw@weilnetz.de>
To: qemu-devel@nongnu.org
Cc: Stefan Weil <sw@weilnetz.de>, Alexander Graf <agraf@suse.de>,
	David Gibson <david@gibson.dropbear.id.au>
Subject: [Qemu-devel] [PATCH] pseries: Fix possible out-of-bounds error
Date: Mon, 21 Nov 2011 20:25:04 +0100	[thread overview]
Message-ID: <1321903504-24287-1-git-send-email-sw@weilnetz.de> (raw)

PCI_NUM_REGIONS is 7, ARRAY_SIZE(bars) is 6. Either bars must be
extended by a 7th array element, or the loop which reads bars[i]
must terminate before it tries to read bars[6].

For dev->io_regions[6].size == 0, the old code also works,
but it is not obvious whether this is always true.

This bug was detected by cppcheck.

Cc: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Stefan Weil <sw@weilnetz.de>
---
 hw/spapr_pci.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/hw/spapr_pci.c b/hw/spapr_pci.c
index 7162588..cefde38 100644
--- a/hw/spapr_pci.c
+++ b/hw/spapr_pci.c
@@ -454,7 +454,7 @@ int spapr_populate_pci_devices(sPAPRPHBState *phb,
         reg[0].size = 0;
 
         n = 0;
-        for (i = 0; i < PCI_NUM_REGIONS; ++i) {
+        for (i = 0; i < PCI_NUM_REGIONS && i < ARRAY_SIZE(bars); ++i) {
             if (0 == dev->io_regions[i].size) {
                 continue;
             }
-- 
1.7.2.5

             reply	other threads:[~2011-11-21 19:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-21 19:25 Stefan Weil [this message]
2011-11-28 17:53 ` [Qemu-devel] [PATCH] pseries: Fix possible out-of-bounds error Stefan Weil
2011-11-29  6:11   ` David Gibson

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=1321903504-24287-1-git-send-email-sw@weilnetz.de \
    --to=sw@weilnetz.de \
    --cc=agraf@suse.de \
    --cc=david@gibson.dropbear.id.au \
    --cc=qemu-devel@nongnu.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;
as well as URLs for NNTP newsgroup(s).