From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41230) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a9URk-00070D-AC for qemu-devel@nongnu.org; Thu, 17 Dec 2015 04:02:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a9URg-0000Lo-6t for qemu-devel@nongnu.org; Thu, 17 Dec 2015 04:02:00 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36966) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a9URg-0000LV-1P for qemu-devel@nongnu.org; Thu, 17 Dec 2015 04:01:56 -0500 From: Gerd Hoffmann Date: Thu, 17 Dec 2015 10:01:48 +0100 Message-Id: <1450342910-26827-5-git-send-email-kraxel@redhat.com> In-Reply-To: <1450342910-26827-1-git-send-email-kraxel@redhat.com> References: <1450342910-26827-1-git-send-email-kraxel@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL 4/6] fw_cfg: avoid calculating invalid current entry pointer List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: "Gabriel L. Somlo" , =?UTF-8?q?Marc=20Mar=C3=AD?= , Gerd Hoffmann From: "Gabriel L. Somlo" When calculating a pointer to the currently selected fw_cfg item, the following is used: FWCfgEntry *e =3D &s->entries[arch][s->cur_entry & FW_CFG_ENTRY_MASK]; When s->cur_entry is FW_CFG_INVALID, we are calculating the address of a non-existent element in s->entries[arch][...], which is undefined. This patch ensures the resulting entry pointer is set to NULL whenever s->cur_entry is FW_CFG_INVALID. Reported-by: Laszlo Ersek Reviewed-by: Laszlo Ersek Signed-off-by: Gabriel Somlo Message-id: 1446733972-1602-5-git-send-email-somlo@cmu.edu Cc: Marc Mar=C3=AD Signed-off-by: Gabriel Somlo Reviewed-by: Laszlo Ersek Signed-off-by: Gerd Hoffmann --- hw/nvram/fw_cfg.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c index c2d3a0a..046fa74 100644 --- a/hw/nvram/fw_cfg.c +++ b/hw/nvram/fw_cfg.c @@ -277,7 +277,8 @@ static int fw_cfg_select(FWCfgState *s, uint16_t key) static uint8_t fw_cfg_read(FWCfgState *s) { int arch =3D !!(s->cur_entry & FW_CFG_ARCH_LOCAL); - FWCfgEntry *e =3D &s->entries[arch][s->cur_entry & FW_CFG_ENTRY_MASK= ]; + FWCfgEntry *e =3D (s->cur_entry =3D=3D FW_CFG_INVALID) ? NULL : + &s->entries[arch][s->cur_entry & FW_CFG_ENTRY_MASK]; uint8_t ret; =20 if (s->cur_entry =3D=3D FW_CFG_INVALID || !e->data || s->cur_offset = >=3D e->len) @@ -342,7 +343,8 @@ static void fw_cfg_dma_transfer(FWCfgState *s) } =20 arch =3D !!(s->cur_entry & FW_CFG_ARCH_LOCAL); - e =3D &s->entries[arch][s->cur_entry & FW_CFG_ENTRY_MASK]; + e =3D (s->cur_entry =3D=3D FW_CFG_INVALID) ? NULL : + &s->entries[arch][s->cur_entry & FW_CFG_ENTRY_MASK]; =20 if (dma.control & FW_CFG_DMA_CTL_READ) { read =3D 1; --=20 1.8.3.1