From 8b43f964f987d44f25df1b7c002d0c241b57bffe Mon Sep 17 00:00:00 2001 From: Lin Ma Date: Mon, 11 Jun 2018 17:23:05 +0800 Subject: net: Fix a potential segfault 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 Cc: qemu-stable@nongnu.org Signed-off-by: Lin Ma Signed-off-by: Jason Wang --- net/net.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'net/net.c') diff --git a/net/net.c b/net/net.c index efb9eaf..2a31339 100644 --- 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 { -- cgit v1.1