From nobody Tue Sep 9 19:23:50 2025 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=1753104173; cv=none; d=zohomail.com; s=zohoarc; b=jAHSGIrTc3vD9+r8gf4wev0bRBgv8XLcHY0IYxYKfBne2mTtJg9dALvvKiAuLygGjBU6s85y0wcYjVImj0b5NBUfm34ynScMX+Ol4MCqsBOZz9zooNyc74dO7QmGDH7VhhtlsWVAst2i6gEjOyiB2ZcMpRNVBRI8mLtvWCbGFhQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1753104173; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=5LKLFozoswm7MmpO/A0cs8F6m/M2NlMstCofUEpJ8Lk=; b=euRcbZkn/ourXUPHg0PyLEmWq1Sweryu+aqevJyX/azfMEQi6wDYm41Q9Tbplu4VRr7bLQ7SgBe2S7QTlMeTakmCfY+9ykS+DGxxhGj0DXi3N/zyz30i+21F0t9B5B57iJycwvnh+3aI0pF74cWWm7HYyIDmlsbJ/uiF3F/MQyQ= 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 1753104173298663.7090095998495; Mon, 21 Jul 2025 06:22:53 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 31BFBCAA; Mon, 21 Jul 2025 09:22:52 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id B6AFAE8A; Mon, 21 Jul 2025 09:21:20 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 24D72DF2; Mon, 21 Jul 2025 09:21:12 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 AE578E01 for ; Mon, 21 Jul 2025 09:21:10 -0400 (EDT) Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-517-jwrfj6rlOY-H-BVBVaFUfw-1; Mon, 21 Jul 2025 09:21:09 -0400 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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 40A6A1800C35 for ; Mon, 21 Jul 2025 13:21:08 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.44.22.25]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6481A180035E for ; Mon, 21 Jul 2025 13:21:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1753104070; 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: in-reply-to:in-reply-to:references:references; bh=ncrgQBzdF4wbDrsC0CZH6rSb6T9t2Tu4L5gxDIB1avo=; b=gUIYD9+MZIM0NLYYwIanv0JNv6T3jdh9YhpKXf5sT05kmKDzEh1Z1QHPoZvgZ1XfC9Finc /2UC4F+s4xtTzRVXrqfuHAaEPSvDI1EZcpOLPva7zSqAhHVjl2zNw8A44/cignT9FhGc9E qWjk5p98y3RU57OciebuZUz96mPCDKc= X-MC-Unique: jwrfj6rlOY-H-BVBVaFUfw-1 X-Mimecast-MFC-AGG-ID: jwrfj6rlOY-H-BVBVaFUfw_1753104068 To: devel@lists.libvirt.org Subject: [PATCH 04/19] virSecuritySELinuxRestoreFileLabel: Refactor cleanup Date: Mon, 21 Jul 2025 15:20:45 +0200 Message-ID: In-Reply-To: References: 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: shrTbyUWlFtUMEYNDRIdT_6Lgfdbw3XoKsHdOVzVias_1753104068 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: ZAUE34DRN75R44U4SPXXCH5Z5PQ2XF56 X-Message-ID-Hash: ZAUE34DRN75R44U4SPXXCH5Z5PQ2XF56 X-MailFrom: pkrempa@redhat.com 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 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: From: Peter Krempa via Devel Reply-To: Peter Krempa X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1753104175242116600 Content-Type: text/plain; charset="utf-8" From: Peter Krempa Automatically free 'fcon' and 'newpath' and remove the 'cleanup' label and 'ret' variable. Signed-off-by: Peter Krempa --- src/security/security_selinux.c | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index 28ac136635..75ad5803a9 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -1526,10 +1526,9 @@ virSecuritySELinuxRestoreFileLabel(virSecurityManage= r *mgr, { bool privileged =3D virSecurityManagerGetPrivileged(mgr); struct stat buf; - char *fcon =3D NULL; - char *newpath =3D NULL; + g_autofree char *fcon =3D NULL; + g_autofree char *newpath =3D NULL; int rc; - int ret =3D -1; /* Some paths are auto-generated, so let's be safe here and do * nothing if nothing is needed. @@ -1544,15 +1543,14 @@ virSecuritySELinuxRestoreFileLabel(virSecurityManag= er *mgr, if (virFileResolveLink(path, &newpath) < 0) { VIR_WARN("cannot resolve symlink %s: %s", path, g_strerror(errno)); - goto cleanup; + return -1; } if ((rc =3D virSecuritySELinuxTransactionAppend(path, NULL, recall, true)) < 0) { - goto cleanup; + return -1; } else if (rc > 0) { - ret =3D 0; - goto cleanup; + return 0; } if (recall) { @@ -1560,10 +1558,9 @@ virSecuritySELinuxRestoreFileLabel(virSecurityManage= r *mgr, if (rc =3D=3D -2) { /* Not supported. Lookup the default label below. */ } else if (rc < 0) { - goto cleanup; + return -1; } else if (rc > 0) { - ret =3D 0; - goto cleanup; + return 0; } } @@ -1571,7 +1568,7 @@ virSecuritySELinuxRestoreFileLabel(virSecurityManager= *mgr, if (stat(newpath, &buf) !=3D 0) { VIR_WARN("cannot stat %s: %s", newpath, g_strerror(errno)); - goto cleanup; + return -1; } if (getContext(mgr, newpath, buf.st_mode, &fcon) < 0) { @@ -1579,19 +1576,14 @@ virSecuritySELinuxRestoreFileLabel(virSecurityManag= er *mgr, * which makes this an expected non error */ VIR_WARN("cannot lookup default selinux label for %s", newpath= ); - ret =3D 0; - goto cleanup; + return 0; } } if (virSecuritySELinuxSetFileconImpl(newpath, fcon, privileged) < 0) - goto cleanup; + return -1; - ret =3D 0; - cleanup: - freecon(fcon); - VIR_FREE(newpath); - return ret; + return 0; } --=20 2.50.0