From nobody Fri Apr 17 09:21:25 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; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1744717902974444.45688754524656; Tue, 15 Apr 2025 04:51:42 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id F162A12EB; Tue, 15 Apr 2025 07:51:41 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 7DCE317B8; Tue, 15 Apr 2025 07:51:12 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 441AA12E4; Tue, 15 Apr 2025 07:51:07 -0400 (EDT) Received: from air.basealt.ru (air.basealt.ru [193.43.8.18]) (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 C166F124A for ; Tue, 15 Apr 2025 07:51:04 -0400 (EDT) Received: from kuznetsovam-nb.office.basealt.ru (unknown [193.43.10.250]) (Authenticated sender: kuznetsovam) by air.basealt.ru (Postfix) with ESMTPSA id E75712336E; Tue, 15 Apr 2025 14:51:02 +0300 (MSK) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 From: Alexander Kuznetsov To: pkrempa@redhat.com, devel@lists.libvirt.org Subject: [PATCH v2 1/1] nss: Fix memory leak in findLease Date: Tue, 15 Apr 2025 14:48:38 +0300 Message-ID: <20250415115038.25084-2-kuznetsovam@altlinux.org> X-Mailer: git-send-email 2.42.4 In-Reply-To: <20250415115038.25084-1-kuznetsovam@altlinux.org> References: <20250415115038.25084-1-kuznetsovam@altlinux.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: JQCFGKKHLYGFOMX6IVAUVOADILHF7WB2 X-Message-ID-Hash: JQCFGKKHLYGFOMX6IVAUVOADILHF7WB2 X-MailFrom: kuznetsovam@altlinux.org 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; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: nickel@altlinux.org, egori@altlinux.org 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-ZM-MESSAGEID: 1744717904470019100 Content-Type: text/plain; charset="utf-8" path is allocated by asprintf() and must be freed later if realloc() fails Restructure the code to allocate=C2=A0path=C2=A0only after=C2=A0realloc()= =C2=A0succeeds, avoiding the need for an extra=C2=A0free() Found by Linux Verification Center (linuxtesting.org) with Svace. Reported-by: Dmitry Fedin Signed-off-by: Alexander Kuznetsov Reviewed-by: Michal Privoznik --- tools/nss/libvirt_nss.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/nss/libvirt_nss.c b/tools/nss/libvirt_nss.c index d79a00a1b0..a1f33ee27b 100644 --- a/tools/nss/libvirt_nss.c +++ b/tools/nss/libvirt_nss.c @@ -137,12 +137,13 @@ findLease(const char *name, =20 if (dlen >=3D 7 && !strcmp(entry->d_name + dlen - 7, ".status")) { char **tmpLease; - if (asprintf(&path, "%s/%s", leaseDir, entry->d_name) < 0) - goto cleanup; - tmpLease =3D realloc(leaseFiles, sizeof(char *) * (nleaseFiles= + 1)); if (!tmpLease) goto cleanup; + + if (asprintf(&path, "%s/%s", leaseDir, entry->d_name) < 0) + goto cleanup; + leaseFiles =3D tmpLease; leaseFiles[nleaseFiles++] =3D path; #if defined(LIBVIRT_NSS_GUEST) --=20 2.42.4