From patchwork Mon Mar 29 16:38:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lukas Straub X-Patchwork-Id: 12170497 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.8 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 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 C1964C433DB for ; Mon, 29 Mar 2021 16:43:28 +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 47FF46191F for ; Mon, 29 Mar 2021 16:43:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 47FF46191F 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]:36438 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lQuz9-0005N6-DT for qemu-devel@archiver.kernel.org; Mon, 29 Mar 2021 12:43:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51696) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lQuuZ-0001iN-Lc for qemu-devel@nongnu.org; Mon, 29 Mar 2021 12:38:43 -0400 Received: from mout.web.de ([212.227.17.12]:44923) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lQuuY-0007gl-1y for qemu-devel@nongnu.org; Mon, 29 Mar 2021 12:38:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1617035920; bh=DaF2NOoBN6091aRooKcdtu/fsO6pM2kOqB+A/5S7bc4=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:In-Reply-To:References; b=OY1laVxPVZhVXTZ4Mz37zzw7NXHFQUqeCcQhaQtI2oKRaB7K4Jnu4PV108ipqO7DF 2UQTQjHL8lWUzAAsOAPXr7vke4UWP/mYkXyo18U8U0G8bezIovle6LSq1Sbk8Sdt1T 2w++MlXwU41++mb/LF5YUeskK1ed+a2eHPx4wVlw= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from gecko.fritz.box ([94.134.180.225]) by smtp.web.de (mrweb102 [213.165.67.124]) with ESMTPSA (Nemesis) id 0MQNiS-1l3w153rZs-00Tjxh; Mon, 29 Mar 2021 18:38:39 +0200 Date: Mon, 29 Mar 2021 18:38:38 +0200 From: Lukas Straub To: qemu-devel Subject: [PATCH v6 2/4] chardev/char.c: Always pass id to chardev_new Message-ID: <3e669b6c160aa7278e37c4d95e0445574f96c7b7.1617035720.git.lukasstraub2@web.de> In-Reply-To: References: MIME-Version: 1.0 X-Provags-ID: V03:K1:EyVERWDMlpwY3pB07coF1luz5pkvptbp+PZAUpxBcPpy83VWDgy zW5bTnQYNN7b2Y5xCjxMCUhuegwkeDp39Z789xbzJDHR0kgkrEV2XVcszMXXYNY6V/RmvOS MV82TqDexEV1hzZaNlVq8ZanqikHCHT0WWQz38H6HaY4E+S9yt+4iX1Zc7rrMqsI/gMG77/ 22XeFFjiDGO6j76BaFb6g== X-UI-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A64rKGovCjuPriAWldlpBnm4oNZ4vvdxqemm8yiOU20y+PRffBc2KVYsS1f3RMty3EahUGw okgDZ4BVwmVKbdtSuiE6PkPXKD3OiBGGtK84UUqbfbdi0MHlHiOS6wwXu3BgK5JzQT6zRZskI 3HEj6bvLNV4UDYyNwFBDQ46lIOoLep+BEhBIRknvBSebeRlIMKrc56pxYRBQ+P1TAEVm8= Received-SPF: pass client-ip=212.227.17.12; 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: Marc-Andre Lureau 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);