]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
net: Fix a potential segfault
authorLin Ma <lma@suse.com>
Mon, 11 Jun 2018 09:23:05 +0000 (17:23 +0800)
committerJason Wang <jasowang@redhat.com>
Fri, 15 Jun 2018 02:39:53 +0000 (10:39 +0800)
If user forgets to provide any backend types for '-netdev' in qemu CLI,
It triggers seg fault.

e.g.

Expected:
$ qemu -netdev id=net0
qemu-system-x86_64: Parameter 'type' is missing

Actual:
$ qemu -netdev id=net0
Segmentation fault (core dumped)

Fixes: 547203ead4327 ("net: List available netdevs with "-netdev help")
Reviewed-by: Thomas Huth <thuth@redhat.com>
Cc: qemu-stable@nongnu.org
Signed-off-by: Lin Ma <lma@suse.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
net/net.c

index efb9eaf7798bcea09e6aee29c750ae7e2b14d963..2a3133990c05d366cfaeb106c82de6e46ff344b3 100644 (file)
--- a/net/net.c
+++ b/net/net.c
@@ -1093,7 +1093,9 @@ static int net_client_init(QemuOpts *opts, bool is_netdev, Error **errp)
     int ret = -1;
     Visitor *v = opts_visitor_new(opts);
 
-    if (is_netdev && is_help_option(qemu_opt_get(opts, "type"))) {
+    const char *type = qemu_opt_get(opts, "type");
+
+    if (is_netdev && type && is_help_option(type)) {
         show_netdevs();
         exit(0);
     } else {