From patchwork Fri Mar 26 07:48:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lukas Straub X-Patchwork-Id: 12165963 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=-10.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 F1112C433DB for ; Fri, 26 Mar 2021 07:50:15 +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 6E70861A32 for ; Fri, 26 Mar 2021 07:50:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6E70861A32 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]:44162 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPhEU-0003vq-Eu for qemu-devel@archiver.kernel.org; Fri, 26 Mar 2021 03:50:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53902) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPhDF-0002dU-Us for qemu-devel@nongnu.org; Fri, 26 Mar 2021 03:48:57 -0400 Received: from mout.web.de ([212.227.15.3]:50581) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPhDE-0002Y5-7x for qemu-devel@nongnu.org; Fri, 26 Mar 2021 03:48:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1616744929; bh=4vX8JCGCMY7S2JtCPus/wvHvOi2j74VvUfJZWFN3jWg=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:In-Reply-To:References; b=hHmu9iJHuyGCRdRtebyNu6Ejf4YXHqCBguuWX76yY87Y1yEbbTRQvAGHF5JtoE/W4 cy/otl+o9fmcE6L4eZJWw2TbiUJrTeTOVdhwLE8pJiGVtRH3TKBD6W3skqsXaZEYOq x7dQyAbBoaV3BSWwhbpzK+QYx8mPjIxBM04or6PI= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from gecko.fritz.box ([89.247.255.242]) by smtp.web.de (mrweb005 [213.165.67.108]) with ESMTPSA (Nemesis) id 1N2jWK-1lmlvp2JRc-013OFD; Fri, 26 Mar 2021 08:48:49 +0100 Date: Fri, 26 Mar 2021 08:48:48 +0100 From: Lukas Straub To: qemu-devel Subject: [PATCH v4 2/4] chardev/char.c: Always pass id to chardev_new Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Provags-ID: V03:K1:wgzPgc5fHJSuoXxxAYRfFfrBsWYGAUo6ceF/vpu5fA10ucmdGdx QM/xy58hzfTecIQaIcqJ9QEjRJfEa4MExpcmn6IoJdBoRU9Qsw4HrqJ4oepAALq/OfWD/ZD +V9SIF04Zq2uImX4BCx9P9ITjL27k/MxC1CG6H7tb1fjhQH//TOQpzpFg+7D+004QGlh+hy CxFS3ixANi1DEeBW8vkXw== X-UI-Out-Filterresults: notjunk:1;V03:K0:87sKQuITj8w=:R5UUYHBMWf8pdG0G1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llPMCySQaySDQ2LWqaAcJ96DHMynYoBrwvX9wyk38QJt 4e93C74Ml7YmakHkbYX3qXHxCSWl8xnYgqr0lX7K/F39DMihX4iwcJ0SuxnWyL9v5wXLXtCCq Te6V0PK+n7SBNBPgDn8uVPpuPN/+SX7ECDrGXtQ+aWZ5CXFcV+bUGizCwnDJAACmA1CYI= Received-SPF: pass client-ip=212.227.15.3; 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: Laurent Vivier , Marc-Andre Lureau , Thomas Huth , Li Zhang , Paolo Bonzini 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);