From nobody Mon Apr 6 23:48:19 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1773768135; cv=none; d=zohomail.com; s=zohoarc; b=jX28IskA5akc8TD4Gd4m5SkBL/6l+qWigkA8afzvsEJmvrKnOE5q0h07WKkpNEHR0cJzXCIVYUMe7bn07BZ9WZ9My+/iD68+YsHPrExj58y8Mag68LSdTs9GEYDMQiCaZ/g43mA87VAye2Cih2RERUqiRmQq4rx9K7cxWOg86Ss= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773768135; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=hVzOsw3MIOOt+Jv9iKjr4crwzYrAKdjgklNI5FGLsLk=; b=EWLPvd+JiE7UfG1k3Yy5Sa33hBvMbxgDKceCCoU8k13YKPc+YlsHjzr1meGfx3DMzujVY6oNU+ehWQAOElPBQUvKiFM8XK+P+36G08KBm/gPM25JS69nNLf54aOegPj/01ECIoAuf6mNMc/PX8vxtqSt/ilunFVMgIOfJCFYcXY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1773768135413616.5288071726914; Tue, 17 Mar 2026 10:22:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w2Y6L-0002nm-4H; Tue, 17 Mar 2026 13:21:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w2Y5y-0002Qo-CI for qemu-devel@nongnu.org; Tue, 17 Mar 2026 13:20:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w2Y5m-0005c5-A2 for qemu-devel@nongnu.org; Tue, 17 Mar 2026 13:20:31 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-504-TahFKnq_P2uFQFlh5I6e-g-1; Tue, 17 Mar 2026 13:20:25 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 48E0D1956094; Tue, 17 Mar 2026 17:20:23 +0000 (UTC) Received: from localhost (unknown [10.44.22.4]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 639E730001A1; Tue, 17 Mar 2026 17:20:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1773768029; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hVzOsw3MIOOt+Jv9iKjr4crwzYrAKdjgklNI5FGLsLk=; b=V0sHPS0Qp0IMpUEmnAkMM2bk68/A1l5vM5JgwKUzsN2q6tq+hvPLmwuRbuU7Lj3TYnukPm SR35agb8H3ssXwOoVykrxpYt2W3gWfUftoNoffnH1H7SqZMWXOMUD4puYmemd4eloBV4Vu L3rWC0oEUGIdPi1+9XKhppGf69Jj/rQ= X-MC-Unique: TahFKnq_P2uFQFlh5I6e-g-1 X-Mimecast-MFC-AGG-ID: TahFKnq_P2uFQFlh5I6e-g_1773768023 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Dmitry Osipenko , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , "Michael S. Tsirkin" , Christian Schoenebeck , Ani Sinha , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann , Zhao Liu , Marcel Apfelbaum , Yanan Wang , Akihiko Odaki , Nikolai Barybin Subject: [PULL 09/16] dump: enhance dump_state_prepare fd initialization Date: Tue, 17 Mar 2026 21:19:09 +0400 Message-ID: <20260317171916.438575-10-marcandre.lureau@redhat.com> In-Reply-To: <20260317171916.438575-1-marcandre.lureau@redhat.com> References: <20260317171916.438575-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.819, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.903, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1773768137310158501 From: Nikolai Barybin Initializing descriptor with zero is unsafe: during cleanup we risk to unconditional close of fd =3D=3D 0 in case dump state wasn't fully initialized. Thus, let's init fd with -1 value and check its value before closing it. Signed-off-by: Nikolai Barybin Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Marc-Andr=C3=A9 Lureau Message-Id: <20250911123656.413160-2-nikolai.barybin@virtuozzo.com> --- dump/dump.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/dump/dump.c b/dump/dump.c index 80ed6c8d219..1f216e74f5f 100644 --- a/dump/dump.c +++ b/dump/dump.c @@ -104,7 +104,10 @@ static int dump_cleanup(DumpState *s) =20 guest_phys_blocks_free(&s->guest_phys_blocks); memory_mapping_list_free(&s->list); - close(s->fd); + if (s->fd !=3D -1) { + close(s->fd); + } + s->fd =3D -1; g_free(s->guest_note); g_clear_pointer(&s->string_table_buf, g_array_unref); s->guest_note =3D NULL; @@ -1709,8 +1712,8 @@ static DumpState dump_state_global =3D { .status =3D = DUMP_STATUS_NONE }; =20 static void dump_state_prepare(DumpState *s) { - /* zero the struct, setting status to active */ - *s =3D (DumpState) { .status =3D DUMP_STATUS_ACTIVE }; + /* zero the struct, setting status to active and fd to -1 */ + *s =3D (DumpState) { .fd =3D -1, .status =3D DUMP_STATUS_ACTIVE }; } =20 bool qemu_system_dump_in_progress(void) --=20 2.53.0