qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Lei Li <lilei@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: Lei Li <lilei@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH] net: avoid segfault in case netdev_del non-host network device
Date: Thu,  1 Nov 2012 15:48:28 +0800	[thread overview]
Message-ID: <1351756108-27192-1-git-send-email-lilei@linux.vnet.ibm.com> (raw)

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 <lilei@linux.vnet.ibm.com>
---
 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

             reply	other threads:[~2012-11-01  7:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-01  7:48 Lei Li [this message]
2012-11-01  9:42 ` [Qemu-devel] [PATCH] net: avoid segfault in case netdev_del non-host network device Stefan Hajnoczi
2012-11-02  2:10   ` Lei Li
2012-11-02  7:38     ` Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1351756108-27192-1-git-send-email-lilei@linux.vnet.ibm.com \
    --to=lilei@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).