From patchwork Mon Mar 11 09:20:20 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 226505 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 53A292C0293 for ; Mon, 11 Mar 2013 20:21:19 +1100 (EST) Received: from localhost ([::1]:37391 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UEyuz-0002dG-FO for incoming@patchwork.ozlabs.org; Mon, 11 Mar 2013 05:21:17 -0400 Received: from eggs.gnu.org ([208.118.235.92]:49913) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UEyuI-0002Xf-CG for qemu-devel@nongnu.org; Mon, 11 Mar 2013 05:20:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UEyuD-0001sp-By for qemu-devel@nongnu.org; Mon, 11 Mar 2013 05:20:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:26167) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UEyuD-0001sj-4k for qemu-devel@nongnu.org; Mon, 11 Mar 2013 05:20:29 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r2B9KSg4012861 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 11 Mar 2013 05:20:28 -0400 Received: from localhost (ovpn-112-19.ams2.redhat.com [10.36.112.19]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r2B9KReD012460; Mon, 11 Mar 2013 05:20:28 -0400 From: Stefan Hajnoczi To: Date: Mon, 11 Mar 2013 10:20:20 +0100 Message-Id: <1362993621-30993-2-git-send-email-stefanha@redhat.com> In-Reply-To: <1362993621-30993-1-git-send-email-stefanha@redhat.com> References: <1362993621-30993-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Anthony Liguori , Stefan Hajnoczi , "Michael S. Tsirkin" Subject: [Qemu-devel] [PATCH 1/2] pci: refuse empty ROM files X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org A zero size ROM file is invalid and should produce a warning. Attempting to use a zero size file ends up hitting an assertion qemu_ram_set_idstr() because RAMBlocks with duplicate addresses are allocated - due to zero size the allocator doesn't increment the next available RAMBlock offset. Also convert __FUNCTION__ to __func__ while we're touching this code. There are no other __FUNCTION__ instances in pci.c anymore. Reported-by: Milos Ivanovic Signed-off-by: Stefan Hajnoczi --- hw/pci/pci.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 2f45c8f..9d5907c 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -1852,7 +1852,12 @@ static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom) size = get_image_size(path); if (size < 0) { error_report("%s: failed to find romfile \"%s\"", - __FUNCTION__, pdev->romfile); + __func__, pdev->romfile); + g_free(path); + return -1; + } else if (size == 0) { + error_report("%s: ignoring empty romfile \"%s\"", + __func__, pdev->romfile); g_free(path); return -1; }