From nobody Sun Sep 28 16:35:30 2025 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=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1757594326; cv=none; d=zohomail.com; s=zohoarc; b=DbLIVauS7n/J8zv7UnLoGfn3f4i9SM/EAmSBPoncLepCpss2a2TLnf97ilbYEL/VqXFsGM0e5hqRE9JKNmghlnu2RKmJRQHo9iaXM+Emlooxp/2byvEVjLyKifIiKrfqPz7IcxQGgkbSIg9oTe3zPKkP/624JEyywwBIGdL1//0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757594326; 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=VMrzAOVoxGmOJ9Ov4Dc6WuTDHNAHSRK4xVAkb+787ek=; b=IFr9zuju+jVVBJbiwc+JS8qZz9oP8r59m5ddxFFMo6nzg/jX/Gcmx+IUh7JKRtNaxT7qz3+JuJA1ZClk4p7g14NpTYwF3fw3rOeAoRtRBNvH2jxac4aGfXDa2Kp1SAedoTCvGtTM9QwDQP7PB/uyT2KtgvuEUhDDNqwLVjygJzU= 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 1757594326708175.87161467591113; Thu, 11 Sep 2025 05:38:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uwgYX-00049l-Bd; Thu, 11 Sep 2025 08:37:41 -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 1uwgYF-00042S-BR for qemu-devel@nongnu.org; Thu, 11 Sep 2025 08:37:24 -0400 Received: from relay.virtuozzo.com ([130.117.225.111]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uwgY2-0003Ld-6R for qemu-devel@nongnu.org; Thu, 11 Sep 2025 08:37:20 -0400 Received: from [130.117.225.5] (helo=dev012.ch-qa.vzint.dev) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1uwg2t-009znU-1D; Thu, 11 Sep 2025 14:36:54 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=Content-Type:MIME-Version:Message-ID:Date:Subject :From; bh=VMrzAOVoxGmOJ9Ov4Dc6WuTDHNAHSRK4xVAkb+787ek=; b=NYufPtr4WZjT1br67w5 aGHy5Hyy+Yei2JEJnb/RnLrkSNdPXC3Qt5HRdlwuRIxHgSIjmGNzsimqZ+6hVM/Y6e3P/YPcwUl0s aeu3eE1rOCPmu+yNDc+0xjEeRE9aPT6rtX1wOH7tt+n76G2Y4zkskuHUIZ5FgFUvnL4LFCirVGp8f 3PxlgAxpddlQzqh7tfuxiQij46fe+K8ZpsN4/fp1N2d6kbvNrHN+33MtdkTxiYE7cvBI8pyCItGfp EHJP51+RVB4tgo62tEFk2AQuWO/dWYmneAhG1JpOetC8dJiV8DJPyEHlAJECNDbpbRkQOaqYvKuS7 OEQjfXknHmVg0qw==; From: Nikolai Barybin To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Nikolai Barybin , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , "Denis V . Lunev" , Ani Sinha Subject: [PATCH v4 1/2] dump: enhance dump_state_prepare fd initialization Date: Thu, 11 Sep 2025 15:36:55 +0300 Message-ID: <20250911123656.413160-2-nikolai.barybin@virtuozzo.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250911123656.413160-1-nikolai.barybin@virtuozzo.com> References: <20250911123656.413160-1-nikolai.barybin@virtuozzo.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=130.117.225.111; envelope-from=nikolai.barybin@virtuozzo.com; helo=relay.virtuozzo.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=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.29 Precedence: list List-Id: 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 @virtuozzo.com) X-ZM-MESSAGEID: 1757594327749116600 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 --- dump/dump.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/dump/dump.c b/dump/dump.c index 15bbcc0c61..b2f7ea7abd 100644 --- a/dump/dump.c +++ b/dump/dump.c @@ -103,7 +103,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; @@ -1708,8 +1711,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.43.5