From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:52052) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TbvcJ-0004g5-SF for qemu-devel@nongnu.org; Fri, 23 Nov 2012 10:56:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TbvcI-0000nL-R2 for qemu-devel@nongnu.org; Fri, 23 Nov 2012 10:56:35 -0500 Received: from mail-ie0-f173.google.com ([209.85.223.173]:56771) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TbvcI-0000me-Mw for qemu-devel@nongnu.org; Fri, 23 Nov 2012 10:56:34 -0500 Received: by mail-ie0-f173.google.com with SMTP id e13so3265827iej.4 for ; Fri, 23 Nov 2012 07:56:34 -0800 (PST) Sender: Paolo Bonzini From: Paolo Bonzini Date: Fri, 23 Nov 2012 16:56:18 +0100 Message-Id: <1353686178-27520-3-git-send-email-pbonzini@redhat.com> In-Reply-To: <1353686178-27520-1-git-send-email-pbonzini@redhat.com> References: <1353686178-27520-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH 1.3 2/2] hmp: do not crash on invalid SCSI hotplug List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: aliguori@us.ibm.com, armbru@redhat.com, lcapitulino@redhat.com Commit 0d93692 (qdev: Convert busses to QEMU Object Model, 2012-05-02) removed a check on the type of the bus where a SCSI disk is hotplugged. However, hot-plugging to the wrong kind of device now causes a crash due to either a NULL pointer dereference (avoided by the previous patch) or a failed QOM cast. Instead, in this case we need to use object_dynamic_cast and check for the result, similar to what was done before that commit. Reported-by: Markus Armbruster Signed-off-by: Paolo Bonzini --- hw/pci-hotplug.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/hw/pci-hotplug.c b/hw/pci-hotplug.c index e7fb780..0ca5546 100644 --- a/hw/pci-hotplug.c +++ b/hw/pci-hotplug.c @@ -80,7 +80,13 @@ static int scsi_hot_add(Monitor *mon, DeviceState *adapter, SCSIBus *scsibus; SCSIDevice *scsidev; - scsibus = SCSI_BUS(QLIST_FIRST(&adapter->child_bus)); + scsibus = (SCSIBus *) + object_dynamic_cast(OBJECT(QLIST_FIRST(&adapter->child_bus)), + TYPE_SCSI_BUS); + if (!scsibus) { + error_report("Device is not a SCSI adapter"); + return -1; + } /* * drive_init() tries to find a default for dinfo->unit. Doesn't -- 1.8.0