From patchwork Wed Oct 24 12:34:12 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 193759 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 AC9C02C0123 for ; Wed, 24 Oct 2012 23:34:34 +1100 (EST) Received: from localhost ([::1]:45917 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TR0AK-0004D7-Ar for incoming@patchwork.ozlabs.org; Wed, 24 Oct 2012 08:34:32 -0400 Received: from eggs.gnu.org ([208.118.235.92]:54953) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TR0AD-0004Co-A2 for qemu-devel@nongnu.org; Wed, 24 Oct 2012 08:34:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TR0A8-00038l-Ma for qemu-devel@nongnu.org; Wed, 24 Oct 2012 08:34:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35313) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TR0A8-00038Y-EH for qemu-devel@nongnu.org; Wed, 24 Oct 2012 08:34:20 -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 q9OCYIpt021375 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 24 Oct 2012 08:34:18 -0400 Received: from localhost (dhcp-64-10.muc.redhat.com [10.32.64.10]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q9OCYH9L032140; Wed, 24 Oct 2012 08:34:18 -0400 From: Stefan Hajnoczi To: Date: Wed, 24 Oct 2012 14:34:12 +0200 Message-Id: <1351082052-13387-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: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: Stefan Hajnoczi Subject: [Qemu-devel] [PATCH] net: Reject non-netdevs in qmp_netdev_del() 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 The netdev_del command crashes when given a -net device, because it calls qemu_opts_del(NULL). Check that this is a -netdev before attempting to delete it and the QemuOpts. Note the subtle change from qemu_find_opts_err("netdev", errp) to qemu_find_opts_err("netdev", NULL). Since "netdev" is a built in options group and we don't check for NULL return anyway, there's no use in passing errp here. Signed-off-by: Stefan Hajnoczi --- net.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/net.c b/net.c index ae4bc0d..e8ae13e 100644 --- a/net.c +++ b/net.c @@ -827,6 +827,7 @@ exit_err: void qmp_netdev_del(const char *id, Error **errp) { NetClientState *nc; + QemuOpts *opts; nc = qemu_find_netdev(id); if (!nc) { @@ -834,8 +835,14 @@ void qmp_netdev_del(const char *id, Error **errp) return; } + opts = qemu_opts_find(qemu_find_opts_err("netdev", NULL), id); + if (!opts) { + error_setg(errp, "Device '%s' is not a netdev", id); + return; + } + qemu_del_net_client(nc); - qemu_opts_del(qemu_opts_find(qemu_find_opts_err("netdev", errp), id)); + qemu_opts_del(opts); } void print_net_client(Monitor *mon, NetClientState *nc)