From patchwork Mon Jun 11 07:06:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lin Ma X-Patchwork-Id: 927514 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="old2LB8u"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4143zc5QcSz9rvt for ; Mon, 11 Jun 2018 17:09:31 +1000 (AEST) Received: from localhost ([::1]:46840 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSGxC-0001Ht-Vp for incoming@patchwork.ozlabs.org; Mon, 11 Jun 2018 03:09:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45014) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSGwr-0001Fn-2x for qemu-devel@nongnu.org; Mon, 11 Jun 2018 03:09:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSGwl-0003RE-It for qemu-devel@nongnu.org; Mon, 11 Jun 2018 03:09:05 -0400 Received: from mail-pf0-x244.google.com ([2607:f8b0:400e:c00::244]:46315) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fSGwl-0003QW-Bu for qemu-devel@nongnu.org; Mon, 11 Jun 2018 03:08:59 -0400 Received: by mail-pf0-x244.google.com with SMTP id q1-v6so9720095pff.13 for ; Mon, 11 Jun 2018 00:08:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id; bh=Vd3AzVDw1DLm12jWjsicZRJxmXEvto3dK2FrusNVnPA=; b=old2LB8ued1B3rphLjQGPyMId1O9MSqYWmN/eNc4Cob8KJcakCJlsFh4g/MvIi3fUH o3xaCMXpYZNWS4HUBbwRajZgyR5tgdnEOl+7lPWRU8NrF/yCtVXxywv92CHwY7dD6DNV Zr8BPkrFkOoCcUcmGsGIt2VN/gA0JPrHrpwdCG6oR/S/gM+lhMt+8qzz2LozEyoFilSV 0WnCY9UKfEIGHcKo1zZJef0XgWvUCVbO+q9T+KlnST5SMsNX1zYmItJovXEuGXy+D7Hp RhusS7y3VdTW8hNUjwdWdWIfWaFCaEy8JC57a9U642R4Pr2h0bE9G4XWaw8vr55XJj7X we+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=Vd3AzVDw1DLm12jWjsicZRJxmXEvto3dK2FrusNVnPA=; b=qWrP3Mw+p0G2slZgGW93zzs5j03tq7qfnDyYI0mcV54Qg1ivsdHCAUVDG8pXJve25f kHlk+2/Jdzs8tgx3xU0e1QphPGrcjP6GCF0eVGgz2ZWGP8v2vK6oBfeuoK8xUS1UVYy4 P/P256CovY1hc+czShw9wDrLqEYLRcV3qS4pCD+64iAbQ/DuX1Vv7gu6gNUyQJ/5akqs oRLdKwVYm+EkTXEDsG2553LJZIUyEbx7cTz0qK5aJzdJL/OvcdTDBA/0X5CPa0tBTkT7 UXSLZe1/nuCpANMfFFZwX1/ZOWqpBK4uQlEePo47d0301bNRyR7cY8waxesR0eg42cf5 bxhQ== X-Gm-Message-State: APt69E3YIVNtoYTDd8jkOpGXWx+yotY7ECUSzhV3NMZX4MHM8AQ5z/s3 jg7qu+BYN6LIj/bRbh/PDVh56w== X-Google-Smtp-Source: ADUXVKLPKkf8DzxozDwiM0+BGh3+DrT8+OSZJoAVz8DC5h/tPMwYpqB4GMw3w2xI23F20S6KazErAg== X-Received: by 2002:a63:618f:: with SMTP id v137-v6mr13966477pgb.145.1528700938305; Mon, 11 Jun 2018 00:08:58 -0700 (PDT) Received: from localhost.localdomain ([45.122.156.254]) by smtp.gmail.com with ESMTPSA id o77-v6sm79879901pfj.0.2018.06.11.00.08.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Jun 2018 00:08:57 -0700 (PDT) From: Lin Ma To: qemu-devel@nongnu.org Date: Mon, 11 Jun 2018 15:06:09 +0800 Message-Id: <20180611070609.9482-1-lma@suse.com> X-Mailer: git-send-email 2.15.1 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::244 Subject: [Qemu-devel] [PATCH v2] net: Fix a potential segfault X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: thuth@redhat.com, jasowang@redhat.com, Lin Ma Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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) Signed-off-by: Lin Ma --- net/net.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/net/net.c b/net/net.c index efb9eaf779..f89790be4a 100644 --- a/net/net.c +++ b/net/net.c @@ -1093,9 +1093,12 @@ 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"))) { - show_netdevs(); - exit(0); + if (is_netdev) { + const char *type = qemu_opt_get(opts, "type"); + if (type && is_help_option(type)) { + show_netdevs(); + exit(0); + } } else { /* Parse convenience option format ip6-net=fec0::0[/64] */ const char *ip6_net = qemu_opt_get(opts, "ipv6-net");