From patchwork Mon Jun 11 09:23:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lin Ma X-Patchwork-Id: 10457433 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 22442602C8 for ; Mon, 11 Jun 2018 09:26:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1CE5A281B7 for ; Mon, 11 Jun 2018 09:26:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1148428329; Mon, 11 Jun 2018 09:26:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A9EB5281B7 for ; Mon, 11 Jun 2018 09:26:16 +0000 (UTC) Received: from localhost ([::1]:47321 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSJ5b-00071g-K9 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 11 Jun 2018 05:26:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39208) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSJ4x-0006eP-MO for qemu-devel@nongnu.org; Mon, 11 Jun 2018 05:25:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSJ4u-0008K2-FT for qemu-devel@nongnu.org; Mon, 11 Jun 2018 05:25:35 -0400 Received: from mail-pf0-x242.google.com ([2607:f8b0:400e:c00::242]:39318) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fSJ4u-0008Jk-Ai for qemu-devel@nongnu.org; Mon, 11 Jun 2018 05:25:32 -0400 Received: by mail-pf0-x242.google.com with SMTP id r11-v6so9918593pfl.6 for ; Mon, 11 Jun 2018 02:25:32 -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=t6DxS9taGDEc3xiR63jLn0QC41sjRJ6FgrGnetJRBj4=; b=nkDcW5Z127qDbDUeTUHAvD3ctTpK9DoSDC4NYqA0714tozV6hwyGx5Osp/fzxOM244 aEvvzTQShoqUZkdlks3g8V5zEDolpmoqpD4/wvtJqK1LMTP1UWDSXmIgz1UFC4ZWjFXQ 9acM1OEbrb8C8qKNUPH82bkzqNU9J1FvS551vEJT0oK+HN8aqP43lqqKyDTDqMyWwi1O sPuZNZTB/MArkheoC8Cy2JtvH21U1M8hOAe9xeSnJzEYWgE0vIXV3+XuM59RHJOFnUUJ DZGv+SYFUuDddNNWzKwzY7zuKbDIPrJpEe7u8Rv1PCY+h5V/Wl/Bio0zn44zShlAryWm 6oIg== 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=t6DxS9taGDEc3xiR63jLn0QC41sjRJ6FgrGnetJRBj4=; b=fm4Dvz4TzuQLJ1O5ZRlr4bY+6XczGIyy6fWLkOudeg0Vx6rzGiNxFoKopPyBXJSy+z YeRFaMgGv68rW+dP82ubEfUm1zUALLCMnd2sEqz1rmfN2CZZvhG/afz55r4o2vW+OW6M c3jhpj0w/TMrOyfnP5juUOSFZSHumq11s/PwLh6w0171hMmEwyYLxVEsnqDM4WZusB32 CCiCg0l+DcLVv4lVPNUntTp7+bkQ/4eLV4PhMm4PX3yMbD3xW0V0qcMaggWc3Q87LDFW pzEE/QUJWwH6EG48cKvuNcqT1w7V4e2LeuHmlnB8fKodnnO0aLrWqtfWeK5iXwZ1b37g 9ybA== X-Gm-Message-State: APt69E3ZJP5VVBDaefJ0tQpqNP07NLE0lgMe73z6SbimYQEb4Vpb5/GK Y7YIsmBYCNaMjTnaE2KZdFzWqQ== X-Google-Smtp-Source: ADUXVKIOj3Hj+nfsibP+MCw/5BqaM4QQCZ8+O/myN6BbCJ+NokXUzAUKeilmX5ixKW1oGeG0MDD8Vg== X-Received: by 2002:a65:4b04:: with SMTP id r4-v6mr11373929pgq.26.1528709130960; Mon, 11 Jun 2018 02:25:30 -0700 (PDT) Received: from localhost.localdomain ([45.122.156.254]) by smtp.gmail.com with ESMTPSA id k80-v6sm93229545pfa.168.2018.06.11.02.25.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Jun 2018 02:25:29 -0700 (PDT) From: Lin Ma To: qemu-devel@nongnu.org Date: Mon, 11 Jun 2018 17:23:05 +0800 Message-Id: <20180611092305.2542-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::242 Subject: [Qemu-devel] [PATCH v3] 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Thomas Huth --- net/net.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/net.c b/net/net.c index efb9eaf779..2a3133990c 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 {