qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] net: Reject non-netdevs in qmp_netdev_del()
@ 2012-10-24 12:34 Stefan Hajnoczi
  2012-11-01 10:06 ` Stefan Hajnoczi
  0 siblings, 1 reply; 2+ messages in thread
From: Stefan Hajnoczi @ 2012-10-24 12:34 UTC (permalink / raw)
  To: qemu-devel; +Cc: Stefan Hajnoczi

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 <stefanha@redhat.com>
---
 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)
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Qemu-devel] [PATCH] net: Reject non-netdevs in qmp_netdev_del()
  2012-10-24 12:34 [Qemu-devel] [PATCH] net: Reject non-netdevs in qmp_netdev_del() Stefan Hajnoczi
@ 2012-11-01 10:06 ` Stefan Hajnoczi
  0 siblings, 0 replies; 2+ messages in thread
From: Stefan Hajnoczi @ 2012-11-01 10:06 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: qemu-devel

On Wed, Oct 24, 2012 at 02:34:12PM +0200, Stefan Hajnoczi wrote:
> 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 <stefanha@redhat.com>
> ---
>  net.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)

Applied to the net tree:
https://github.com/stefanha/qemu/commits/net

Stefan

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-11-01 10:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-24 12:34 [Qemu-devel] [PATCH] net: Reject non-netdevs in qmp_netdev_del() Stefan Hajnoczi
2012-11-01 10:06 ` Stefan Hajnoczi

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).