From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:40879) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tcy93-0005aB-BG for qemu-devel@nongnu.org; Mon, 26 Nov 2012 07:50:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tcy91-0000UF-VD for qemu-devel@nongnu.org; Mon, 26 Nov 2012 07:50:41 -0500 Received: from mx1.redhat.com ([209.132.183.28]:3786) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tcy91-0000Te-N8 for qemu-devel@nongnu.org; Mon, 26 Nov 2012 07:50:39 -0500 Date: Mon, 26 Nov 2012 10:50:32 -0200 From: Luiz Capitulino Message-ID: <20121126105032.78103804@doriath.home> In-Reply-To: <1353686178-27520-3-git-send-email-pbonzini@redhat.com> References: <1353686178-27520-1-git-send-email-pbonzini@redhat.com> <1353686178-27520-3-git-send-email-pbonzini@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [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: Paolo Bonzini Cc: aliguori@us.ibm.com, qemu-devel@nongnu.org, armbru@redhat.com On Fri, 23 Nov 2012 16:56:18 +0100 Paolo Bonzini wrote: > 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 As far as HMP is concerned this looks good. > --- > 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