From nobody Sun Dec 22 02:43:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1732893492528360.63748842188704; Fri, 29 Nov 2024 07:18:12 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id CA8431975; Fri, 29 Nov 2024 10:18:11 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 900B1BF7; Fri, 29 Nov 2024 10:17:55 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id C7CB91952; Fri, 29 Nov 2024 09:57:05 -0500 (EST) Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id D47211768 for ; Fri, 29 Nov 2024 09:57:04 -0500 (EST) Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-212348d391cso15824185ad.2 for ; Fri, 29 Nov 2024 06:57:04 -0800 (PST) Received: from localhost.localdomain ([120.229.53.164]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-215218f1d99sm31672835ad.44.2024.11.29.06.57.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Nov 2024 06:57:03 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-1.7 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732892224; x=1733497024; darn=lists.libvirt.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=4SCI1yfd8pFqAS/NU/xyLwSE4UoaXg5+sA4L0wq/Jto=; b=f3V7xizt0g37QlawTs9JZauR5+DzGeq44oguFRBtAQcugJu2JH/OzLsditkQ+Ya3CZ x9tJ14drKbr7iSGo+fh1vjxu8fgnQYn1d2dA7JeniDEvht9QKGgdrdyFh8AaZRU61QIX 4tZQIUd0+zx5JD03ZaxW5RMPl4MlgirD1od4xlkezanMCR/g/FlFsy2BrePMJZ914tBN 6y0U5a3RPAJRlFlK4pUt+Jp3QC5lpMb/4rQKmpuSvF5+CBpXCnePWyGE7k69LC+TyQdj cEDli1Wwp1hn1JVjBcs6bw+yXKpWpURk7troPEG7zZyjbxtA/M1cwu9AirT7VJrMlZZM coMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732892224; x=1733497024; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=4SCI1yfd8pFqAS/NU/xyLwSE4UoaXg5+sA4L0wq/Jto=; b=VS3CiBFBBaLTLGDoQVG9Xz3gUdK8pmcwIOU+si6K3m9cr40lYuSGhL/6A+j0oQFbuB RB6tM47XOmvlZDsSXHe0LCK8xKv4ArH3/Ji4uUETgUAGtnH8weX2ZBXh+7SXKBIDalBY B0TEgdW+S/5wjUTg4iw9IZ3R0vz48LdM4tc/HvcHdQa7l3zZNhYU/uLFOQMo+kgE3glh W4vo3TfB41mXFdJL+NfXzsdtAp+Odi1Rj/qlJzwH/PaFXC1bLyHNur8wgyF0/bz9A1j4 va6kFsXBGfJ/gB9v5xFqaq5ZB0ok4gBKs1700jZWNnZCe5+0PXLh6BLhD3jezgNm65Bb 48fg== X-Gm-Message-State: AOJu0YzNkFwKWfJ6jLBvamu/caslJCxLXkwABJ9pIA+z3wswrE6CsS1N c7GCyNUB+Gdla6GC7HUS2lRKcCD7hMwm+RJDYpS/IbG0izT27U8+hx80TaDD X-Gm-Gg: ASbGncsr8SpN0Rc2C+7jNX9nu+7iDhRKzEQb2W0ybM6vF7XoSfJ5P8ZJH8mrMS6F2C3 KU5G4Sj/+xAUwZuNXgYmp0xcuuI6imdJjHqnBZrtQHhrTFG+ZaSZUGx+eBSV+V4d+7/yJLWEwff hE+774oDMFkAf6/JZpFNYBmLQolWcBsQW65NtnYITeNI0a4ULB7HhyJWtBknfgB5UPt49FSSFrV P6I5S3+zF23Jz5kFrIcbYJlTgYuqp8dEcXyF9lG X-Google-Smtp-Source: AGHT+IHLLyTFCitzd6vP3NFqRx8fPriJw8PvDDRPpPqidM1ApREVAgnRmRPnufvqJa9GXsqEg/EqfQ== X-Received: by 2002:a17:902:f601:b0:215:2f00:67b1 with SMTP id d9443c01a7336-2152f0069b2mr85625655ad.6.1732892223649; Fri, 29 Nov 2024 06:57:03 -0800 (PST) From: kaihuan To: devel@lists.libvirt.org Subject: [PATCH] qemuSnapshotDeleteValidate: Fix crash when disk is not found in VM definition Date: Fri, 29 Nov 2024 22:56:45 +0800 Message-Id: <20241129145645.2472-1-jungleman759@gmail.com> X-Mailer: git-send-email 2.33.1.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-MailFrom: jungleman759@gmail.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0 Message-ID-Hash: WVEBRQZZIIDTLQBOTQ3442GLL2NNXXDB X-Message-ID-Hash: WVEBRQZZIIDTLQBOTQ3442GLL2NNXXDB X-Mailman-Approved-At: Fri, 29 Nov 2024 15:17:53 -0500 CC: kaihuan X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1732893497950019100 Content-Type: text/plain; charset="utf-8" qemuDomainDiskByName() can return a NULL pointer on failure. But this returned value in qemuSnapshotDeleteValidate is not checked.It wil= l make libvirtd crash. Signed-off-by: kaihuan --- src/qemu/qemu_snapshot.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index 18b2e478f6..bcbd913073 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -4242,8 +4242,19 @@ qemuSnapshotDeleteValidate(virDomainObj *vm, virDomainDiskDef *vmdisk =3D NULL; virDomainDiskDef *disk =3D NULL; =20 - vmdisk =3D qemuDomainDiskByName(vm->def, snapDisk->name); - disk =3D qemuDomainDiskByName(snapdef->parent.dom, snapDisk->n= ame); + if (!(vmdisk =3D qemuDomainDiskByName(vm->def, snapDisk->name)= )) { + virReportError(VIR_ERR_OPERATION_FAILED, + _("disk '%1$s' referenced by snapshot '%2$s' n= ot found in the current definition"), + snapDisk->name, snap->def->name); + return -1; + } + + if (!(disk =3D qemuDomainDiskByName(snapdef->parent.dom, snapD= isk->name))) { + virReportError(VIR_ERR_OPERATION_FAILED, + _("disk '%1$s' referenced by snapshot '%2$s' n= ot found in the VM definition of the deleted snapshot"), + snapDisk->name, snap->def->name); + return -1; + } =20 if (!virStorageSourceIsSameLocation(vmdisk->src, disk->src)) { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, --=20 2.33.1.windows.1