From nobody Mon Feb 9 03:00:17 2026 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=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1770384804; cv=none; d=zohomail.com; s=zohoarc; b=abDVWOnFqbrgmmEJC7JeI9NSENcv6zzaHAxBTJUykDS7ectBVMdJ0SwMuA36pXqcEzdmD8np5h1imLZui9/N38I/C86EYPbXyTTgTOmADZHWAhwPUJcNwnyqztQItVjvXheLZSWSAvh3k0fGA0KEjRXdksahs9ykA8kWbq1AsMo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770384804; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Subject:Subject:To:To:Message-Id:Cc; bh=ALL7+k083PDUGh2A61zOtoEt9G4b5SUNVoTb7WxLbe4=; b=Hd9VUmYLNVH+CjmBSK+/thIJ2EyuA0nneWsK7KecnufrF8c7cd3mzYdbuHLcGqijbW5JpxXZ1OPLODeW7Ml/qKrWo7dGTydkxGzyf7xPkEJigKjCxFJyYro3iwKHQsqh65AxvdnU9Am7VdWUc7SMCbJX8yIzkd9WnyzDcfRIVmo= ARC-Authentication-Results: i=1; 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=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 177038480450640.325399662651876; Fri, 6 Feb 2026 05:33:24 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id 79453419C7; Fri, 6 Feb 2026 08:33:24 -0500 (EST) Received: from [172.19.199.6] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 6464841B69; Fri, 6 Feb 2026 08:32:43 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id 8B4603F899; Fri, 6 Feb 2026 08:32:39 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 1D2073F961 for ; Fri, 6 Feb 2026 08:32:39 -0500 (EST) 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-691-_sAETPckN0e_mgsI7xrXKA-1; Fri, 06 Feb 2026 08:32:36 -0500 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 BA1361956094 for ; Fri, 6 Feb 2026 13:32:35 +0000 (UTC) Received: from moe (unknown [10.43.3.236]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 23D2418003F5 for ; Fri, 6 Feb 2026 13:32:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770384758; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ALL7+k083PDUGh2A61zOtoEt9G4b5SUNVoTb7WxLbe4=; b=Gej5ePFuH2tc0LpTYmzMdM3U8XJO8ZcqeJvcOFYrte0AUd4KKfPlU+hGo7osuxsa0p8F3N 5T1Evyfs54EQC5WrWqQtD7SoDabO49MsSxNyY5O/4UAlv5F8vOdottFZHKYvxxE0MF6qxe dmhTyUesZfw63hMLqLGvcfdf0OxsB+Y= X-MC-Unique: _sAETPckN0e_mgsI7xrXKA-1 X-Mimecast-MFC-AGG-ID: _sAETPckN0e_mgsI7xrXKA_1770384755 To: devel@lists.libvirt.org Subject: [PATCH] hyperv: Avoid memleak in hypervDomainDefParsePhysicalDisk Date: Fri, 6 Feb 2026 14:32:33 +0100 Message-ID: <6f7f36c6b6421d3c31a657a3a496e5e90e96a386.1770384753.git.mprivozn@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: zz2a_Zc89pOgUFbJSWMn1_a136YYNWbnrmxZ1rJ8yxY_1770384755 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: ZJLW2334X4XWWTQWN2VJ6QVMZY6UQU6X X-Message-ID-Hash: ZJLW2334X4XWWTQWN2VJ6QVMZY6UQU6X X-MailFrom: mprivozn@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1770384817929158500 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik When parsing a physical disk, the @hostResouce is escaped once with the retval being stored into @hostEscaped. Then, it's escaped again, but the retval is stored into the very same variable, leading to a leak where intermediate value is lost. 256 bytes in 1 blocks are definitely lost in loss record 469 of 483 at 0x49543A0: realloc (vg_replace_malloc.c:1804) by 0x516C251: g_realloc (in /usr/lib64/libglib-2.0.so.0.8400.4) by 0x518BB7E: g_string_expand (in /usr/lib64/libglib-2.0.so.0.8400.4) by 0x518BFF9: g_string_insert_len (in /usr/lib64/libglib-2.0.so.0.8400.4) by 0x4A58B5F: g_string_append_len_inline (gstring.h:247) by 0x4A58B5F: virBufferAdd (virbuffer.c:164) by 0x4AFDA71: virStringReplace (virstring.c:708) by 0x4DA4381: hypervDomainDefParsePhysicalDisk (hyperv_driver.c:1375) by 0x4DA4A18: hypervDomainDefParseStorage (hyperv_driver.c:1487) by 0x4DA9E31: hypervDomainGetXMLDesc (hyperv_driver.c:2761) by 0x4DFB3E5: virDomainGetXMLDesc (libvirt-domain.c:2898) by 0x406D39B: cmdDumpXML (virsh-domain.c:10787) by 0x40B13B1: vshCommandRun (vsh.c:1383) Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/hyperv/hyperv_driver.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index 8dd56f39dc..203bbeb8a5 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -1351,6 +1351,7 @@ hypervDomainDefParsePhysicalDisk(hypervPrivate *priv, virDomainDiskDef *disk =3D NULL; char **hostResource =3D entry->data->HostResource.data; g_autofree char *hostEscaped =3D NULL; + g_autofree char *hostEscapedTwice =3D NULL; g_autofree char *driveNumberStr =3D NULL; g_auto(virBuffer) query =3D VIR_BUFFER_INITIALIZER; int addr =3D -1, ctrlr_idx =3D -1; @@ -1373,12 +1374,12 @@ hypervDomainDefParsePhysicalDisk(hypervPrivate *pri= v, =20 /* Query Msvm_DiskDrive for the DriveNumber */ hostEscaped =3D virStringReplace(*hostResource, "\\\"", "\""); - hostEscaped =3D virStringReplace(hostEscaped, "\\", "\\\\"); + hostEscapedTwice =3D virStringReplace(hostEscaped, "\\", "\\\\"); =20 /* quotes must be preserved, so virBufferEscapeSQL can't be used */ virBufferAsprintf(&query, MSVM_DISKDRIVE_WQL_SELECT "WHERE __PATH=3D'%s'", - hostEscaped); + hostEscapedTwice); =20 if (hypervGetWmiClass(Msvm_DiskDrive, &diskdrive) < 0) goto cleanup; --=20 2.52.0