From nobody Tue Sep 9 19:22:20 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=1753104344; cv=none; d=zohomail.com; s=zohoarc; b=MWhjYqrZqxZ/LFCEkVVq5On8erP+ZxgkL5S5Aqpz/5+colGVL69dvScy4BRBKH7zeNhZ3CYp4c9rSJbSRhir3ImAoagU0FNwcuiBuhlFcDa1en2ZGbZdklCL5gBzAoUy2XKJSgSMOoGU1gGlCX6B6gil/jnSmC332m+xCDDRrYs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1753104344; 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=HH4ZLyZ6w8pgSY/sGUMdP51s4DnIMs4pYtVTtyGIuTM=; b=mdROYqEZrmyPPxmK0wXEPUs+XmA6VBI3Wnd4+nNama7tg8EcrkjROQFxhPhgVEqatOSNBz0K0HxwlQnJ+Nk6MrcHuCwDHKOJ+58mgYPQRUfUddSxbuJKzctki9xa7Uyis2Uqhi3yejFnSx0EZFrzjZq2ye/r11NxSF2oh6dEwdk= 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 1753104344644294.4233565152682; Mon, 21 Jul 2025 06:25:44 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id A574D13F6; Mon, 21 Jul 2025 09:25:43 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 5F649149C; Mon, 21 Jul 2025 09:21:41 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 825D511E3; Mon, 21 Jul 2025 09:21:34 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 297F61361 for ; Mon, 21 Jul 2025 09:21:18 -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-616-ZdB--LGvPdGs8LZ9pIHpzQ-1; Mon, 21 Jul 2025 09:21:16 -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 602351800872 for ; Mon, 21 Jul 2025 13:21:15 +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 AB6F718002B6 for ; Mon, 21 Jul 2025 13:21:14 +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=1753104077; 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=3Xkt1ZL5+mnXEU2DQdgKcGUig7KVKYCUIRF1x7VxN1A=; b=O9LVJ1e242yekSwbxL4ULSuLR0kqVFgSyahDmGQe5P2oS3TpVu1qztVpSXcv7TLhRvCRaJ zGjvF0afQ82GXacHPQIeAOMidC3zVMjpVamFveZ5jVsVhGgJpCKQp/Fb2AtSsyofL4ba2O 7TVxElcB8iTFuVxYttt2Jlek787sMXU= X-MC-Unique: ZdB--LGvPdGs8LZ9pIHpzQ-1 X-Mimecast-MFC-AGG-ID: ZdB--LGvPdGs8LZ9pIHpzQ_1753104075 To: devel@lists.libvirt.org Subject: [PATCH 10/19] virSecuritySELinuxSetTapFDLabel: Refactor cleanup Date: Mon, 21 Jul 2025 15:20:51 +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: Z4QwcL4anPO0GB8u-c8xp5PmamVXKsQSKUA6U9B73JI_1753104075 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 3OYPC2KH3YWAQA7ZFICR2DQTH77KM5O4 X-Message-ID-Hash: 3OYPC2KH3YWAQA7ZFICR2DQTH77KM5O4 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: 1753104346232116600 Content-Type: text/plain; charset="utf-8" From: Peter Krempa Automatically free temporary variables and remove the need for 'cleanup' section. Signed-off-by: Peter Krempa --- src/security/security_selinux.c | 35 ++++++++++++++------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index ad789c611f..f01a707c28 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -3459,10 +3459,11 @@ virSecuritySELinuxSetTapFDLabel(virSecurityManager = *mgr, int fd) { struct stat buf; - char *fcon =3D NULL; + g_autofree char *fcon =3D NULL; virSecurityLabelDef *secdef; - char *str =3D NULL, *proc =3D NULL, *fd_path =3D NULL; - int rc =3D -1; + g_autofree char *str =3D NULL; + g_autofree char *proc =3D NULL; + g_autofree char *fd_path =3D NULL; secdef =3D virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX_NAME); if (!secdef || !secdef->label) @@ -3470,13 +3471,13 @@ virSecuritySELinuxSetTapFDLabel(virSecurityManager = *mgr, if (fstat(fd, &buf) < 0) { virReportSystemError(errno, _("cannot stat tap fd %1$d"), fd); - goto cleanup; + return -1; } if ((buf.st_mode & S_IFMT) !=3D S_IFCHR) { virReportError(VIR_ERR_INTERNAL_ERROR, _("tap fd %1$d is not character device"), fd); - goto cleanup; + return -1; } /* Label /dev/tap([0-9]+)? devices only. Leave /dev/net/tun alone! */ @@ -3485,34 +3486,28 @@ virSecuritySELinuxSetTapFDLabel(virSecurityManager = *mgr, if (virFileResolveLink(proc, &fd_path) < 0) { virReportSystemError(errno, _("Unable to resolve link: %1$s"), proc); - goto cleanup; + return -1; } if (!STRPREFIX(fd_path, "/dev/tap")) { VIR_DEBUG("fd=3D%d points to %s not setting SELinux label", fd, fd_path); - rc =3D 0; - goto cleanup; + return 0; } if (getContext(mgr, fd_path, buf.st_mode, &fcon) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot lookup default selinux label for tap fd %= 1$d"), fd); - goto cleanup; + return -1; } - if (!(str =3D virSecuritySELinuxContextAddRange(secdef->label, fcon)))= { - goto cleanup; - } else { - rc =3D virSecuritySELinuxFSetFilecon(fd, str); - } + if (!(str =3D virSecuritySELinuxContextAddRange(secdef->label, fcon))) + return -1; - cleanup: - freecon(fcon); - VIR_FREE(fd_path); - VIR_FREE(proc); - VIR_FREE(str); - return rc; + if (virSecuritySELinuxFSetFilecon(fd, str) < 0) + return -1; + + return 0; } static char * --=20 2.50.0