From patchwork Fri Mar 26 17:35:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lukas Straub X-Patchwork-Id: 12167243 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A028EC433C1 for ; Fri, 26 Mar 2021 17:39:48 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 22204619CB for ; Fri, 26 Mar 2021 17:39:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 22204619CB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=web.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:39036 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPqR1-0001iI-1f for qemu-devel@archiver.kernel.org; Fri, 26 Mar 2021 13:39:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44422) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPqMe-0005Rc-2z for qemu-devel@nongnu.org; Fri, 26 Mar 2021 13:35:16 -0400 Received: from mout.web.de ([217.72.192.78]:44131) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPqMc-0004aC-7l for qemu-devel@nongnu.org; Fri, 26 Mar 2021 13:35:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1616780112; bh=+tezEO/HGYlg8UDCAoZCBB7IPiC45gc/drZqLmnqJCA=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:In-Reply-To:References; b=ptf2v1eS9ydxbxu2dNHA8//ixmBZr9PEkdYrltA5xFnGIuwjO3j2Y5/YRmA2JCahD nYCJuSrUMaZRAeRDSHwiuoza5YLhFpmgl/2zxkNQyf693rbKGBEflJl/s3TLNipS6T 5utqLr9zTMd9H+2IAYfI7y2sea2XQgaH2BwLPxl0= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from gecko.fritz.box ([89.247.255.242]) by smtp.web.de (mrweb102 [213.165.67.124]) with ESMTPSA (Nemesis) id 0MfHfy-1l18TS1aJu-00OmIk; Fri, 26 Mar 2021 18:35:12 +0100 Date: Fri, 26 Mar 2021 18:35:10 +0100 From: Lukas Straub To: Peter Maydell Subject: [PULL 4/6] chardev/char.c: Always pass id to chardev_new Message-ID: <3e669b6c160aa7278e37c4d95e0445574f96c7b7.1616779714.git.lukasstraub2@web.de> In-Reply-To: References: MIME-Version: 1.0 X-Provags-ID: V03:K1:p4aqaNZ128UjSErXZcSTZyCmTehRbHLH+yFfR86eJF7OLcKaxxn 0WR57zxNKrc8dos3ElSir0/lRATHshEJbPhgXuUsRc55/q3mqxSsk3ab64c+tfakyvtE5gL TFCILpeIbKwoUcZNsQwGg0Koy71bSl/hQAz/HdBsh/XG3TvU7TGSPF8RwO3qEn0nzFURmE0 GCxTsc5GZDOBZjB9WSmmQ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hjsG5bKVmhM5Mf4h gBSpGdZc3ljXariLAAyL3oX4/AwUYOTcPlvNOTNxjXFdj70NtNyVaC1rBST+S3Nehk4zGCS+3 BarWMwwDuiMZjr47QBB5q6RNx8KMmn30xiHvE1+2cjZvNGzrYNB16vFcCEH+swXPTpijc9BgC FtRi/orWyvcrtgz38VQk1Wt1y50PRsloPSLcZtfc6pi16dn6wipnw3jDfyeGGIN2AbAfU= Received-SPF: pass client-ip=217.72.192.78; envelope-from=lukasstraub2@web.de; helo=mout.web.de X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Always pass the id to chardev_new, since it is needed to register the yank instance for the chardev. Also, after checking that nothing calls chardev_new with id=NULL, assert() that id!=NULL. This fixes a crash when using chardev-change to change a chardev to chardev-socket, which attempts to register a yank instance. This in turn tries to dereference the NULL-pointer. Signed-off-by: Lukas Straub Reviewed-by: Marc-André Lureau Tested-by: Li Zhang --- chardev/char.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.30.2 diff --git a/chardev/char.c b/chardev/char.c index 48f321b3e1..75993f903f 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -967,6 +967,7 @@ static Chardev *chardev_new(const char *id, const char *typename, bool be_opened = true; assert(g_str_has_prefix(typename, "chardev-")); + assert(id); obj = object_new(typename); chr = CHARDEV(obj); @@ -1095,12 +1096,11 @@ ChardevReturn *qmp_chardev_change(const char *id, ChardevBackend *backend, return NULL; } - chr_new = chardev_new(NULL, object_class_get_name(OBJECT_CLASS(cc)), + chr_new = chardev_new(id, object_class_get_name(OBJECT_CLASS(cc)), backend, chr->gcontext, errp); if (!chr_new) { return NULL; } - chr_new->label = g_strdup(id); if (chr->be_open && !chr_new->be_open) { qemu_chr_be_event(chr, CHR_EVENT_CLOSED);