Received: from eggs.gnu.org ([140.186.70.92]:50725) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RSZV2-00061o-I9 for qemu-devel@nongnu.org; Mon, 21 Nov 2011 14:25:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RSZUy-0001cl-8Q for qemu-devel@nongnu.org; Mon, 21 Nov 2011 14:25:52 -0500 Received: from v220110690675601.yourvserver.net ([78.47.199.172]:41235) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RSZUy-0001Rr-3I for qemu-devel@nongnu.org; Mon, 21 Nov 2011 14:25:48 -0500 From: Stefan Weil Date: Mon, 21 Nov 2011 20:25:04 +0100 Message-Id: <1321903504-24287-1-git-send-email-sw@weilnetz.de> Subject: [Qemu-devel] [PATCH] pseries: Fix possible out-of-bounds error List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Stefan Weil , Alexander Graf , David Gibson 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 Signed-off-by: Stefan Weil --- 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