From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:57199) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TTpWw-0008B4-C5 for qemu-devel@nongnu.org; Thu, 01 Nov 2012 03:49:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TTpWv-0003w0-8x for qemu-devel@nongnu.org; Thu, 01 Nov 2012 03:49:34 -0400 Received: from e28smtp06.in.ibm.com ([122.248.162.6]:41767) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TTpWt-0003ve-VT for qemu-devel@nongnu.org; Thu, 01 Nov 2012 03:49:33 -0400 Received: from /spool/local by e28smtp06.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 1 Nov 2012 13:19:25 +0530 Received: from d28av01.in.ibm.com (d28av01.in.ibm.com [9.184.220.63]) by d28relay04.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id qA17nLAM3670502 for ; Thu, 1 Nov 2012 13:19:22 +0530 Received: from d28av01.in.ibm.com (loopback [127.0.0.1]) by d28av01.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id qA1DJCfk019264 for ; Thu, 1 Nov 2012 13:19:13 GMT From: Lei Li Date: Thu, 1 Nov 2012 15:48:28 +0800 Message-Id: <1351756108-27192-1-git-send-email-lilei@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH] net: avoid segfault in case netdev_del non-host network device List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Lei Li netdev_del assume that remove host network device. However, when try to remove a non-host network device by netdev_del, it will cause a segfault. The reson is that qmp_netdev_del is not checking for a NULL return for qemu_find_opts_err in case find_list did not find the netdev group to delete. Catch this and return an error. (qemu) host_net_add user vlan=1,name=con.1,hostfwd=udp::4111-127.0.0.1:4333 (qemu) info network hub 1 \ con.1: type=user,net=10.0.2.0,restrict=off hub 0 \ user.0: type=user,net=10.0.2.0,restrict=off \ e1000.0: type=nic,model=e1000,macaddr=52:54:00:12:34:56 (qemu) netdev_del con.1 Segmentation fault (core dumped) Signed-off-by: Lei Li --- net.c | 8 +++++++- 1 files changed, 7 insertions(+), 1 deletions(-) diff --git a/net.c b/net.c index ae4bc0d..cc52552 100644 --- a/net.c +++ b/net.c @@ -827,6 +827,7 @@ exit_err: void qmp_netdev_del(const char *id, Error **errp) { NetClientState *nc; + QemuOptsList *opt; nc = qemu_find_netdev(id); if (!nc) { @@ -835,7 +836,12 @@ void qmp_netdev_del(const char *id, Error **errp) } qemu_del_net_client(nc); - qemu_opts_del(qemu_opts_find(qemu_find_opts_err("netdev", errp), id)); + opt = qemu_find_opts_err("netdev", errp); + if (errp) { + error_setg(errp, "Failed to delete %s", id); + return; + } + qemu_opts_del(qemu_opts_find(opt, id)); } void print_net_client(Monitor *mon, NetClientState *nc) -- 1.7.7.6