From nobody Mon Sep 8 17:12:43 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=1753104127; cv=none; d=zohomail.com; s=zohoarc; b=CCklQo0DGA6gY9FoMqAWwXWdJwwcpRhJC9ASusLcVaryrNFFl+1dKqtpC/LQJvmBR4g4cKD9Y6Ur5JPqjBhJg2lR7IHtR8+kuAEELYNTPi2DXjrQtmOgF6aiSh9Mk0sGbM0c8M/I05gaIf5bXS/mENp72eMddxsISVUtTN+8Qe4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1753104127; 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=v7jATS926RP/wAwI7NBD17bVRLM9A/PDlLOdNqOxZJU=; b=UeRc32BWe4EIc3qmdK2t13ovjjVKAVpspiIDZgGEpgKqiHnOHlvX6bkTO1G4VaEjtLB54s9+mr8UG4GXeczhsunY5Oavt/625x5qw14hQebT5KufmsjWtVayKG/4aVPNL2XwNujT6L/krkWnmFKMZtmgEM5OOtT9uD4R/Y0Pem8= 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 1753104127114439.7727950132745; Mon, 21 Jul 2025 06:22:07 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 29D5C14C6; Mon, 21 Jul 2025 09:22:06 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id E5A1D12AE; Mon, 21 Jul 2025 09:21:16 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id E11E5D4D; Mon, 21 Jul 2025 09:21:11 -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 7515FC67 for ; Mon, 21 Jul 2025 09:21:07 -0400 (EDT) Received: from mx-prod-mc-03.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-483-cCQD4DiEOiKU9tNztTiDSA-1; Mon, 21 Jul 2025 09:21:05 -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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 88FF019560B7 for ; Mon, 21 Jul 2025 13:21:04 +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 91BEB1801AEA for ; Mon, 21 Jul 2025 13:21:03 +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=1753104067; 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=gdDRIhnUcagYEnZhQIaA0s922jrCjLp29ypv45wy/+8=; b=Qo5xedDmWVCXp+e/yygAgtzYXqK8OfZtrUZDI1W4tJRpK93Ej8i2qRCWS7sHEXzK1+Q+4X QOxvKvtRWvcYqO1YOoL4G+pEPKc9DZ9dX0XAvKzk6APPZYtl3FY9vURTqC7U5eC1xEvo7L BrXxREYIOqI6FDtCZRU4iWV9Pt2EjP8= X-MC-Unique: cCQD4DiEOiKU9tNztTiDSA-1 X-Mimecast-MFC-AGG-ID: cCQD4DiEOiKU9tNztTiDSA_1753104064 To: devel@lists.libvirt.org Subject: [PATCH 01/19] security/security_driver.c/h: Fix function header formatting Date: Mon, 21 Jul 2025 15:20:42 +0200 Message-ID: <71b547147519d377cd808c9e6e3101094b8cccda.1753103831.git.pkrempa@redhat.com> 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: jZAmm-VIlkLtouh-f8ZZcjj8y7k279vwlHp34fT7O9E_1753104064 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: QSF477JWVKI4T2RLFEB3LRVKTC4YTUGA X-Message-ID-Hash: QSF477JWVKI4T2RLFEB3LRVKTC4YTUGA 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: 1753104128782116600 Content-Type: text/plain; charset="utf-8" From: Peter Krempa Fix the misaligned arguments by switching over to modern style. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/security/security_driver.c | 5 +++-- src/security/security_driver.h | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/security/security_driver.c b/src/security/security_driver.c index ae11f595eb..4cb270e836 100644 --- a/src/security/security_driver.c +++ b/src/security/security_driver.c @@ -45,8 +45,9 @@ static virSecurityDriver *security_drivers[] =3D { &virSecurityDriverNop, /* Must always be last, since it will always pr= obe */ }; -virSecurityDriver *virSecurityDriverLookup(const char *name, - const char *virtDriver) +virSecurityDriver * +virSecurityDriverLookup(const char *name, + const char *virtDriver) { virSecurityDriver *drv =3D NULL; size_t i; diff --git a/src/security/security_driver.h b/src/security/security_driver.h index 5ab4d6ca1e..b8c5b416e3 100644 --- a/src/security/security_driver.h +++ b/src/security/security_driver.h @@ -245,5 +245,6 @@ struct _virSecurityDriver { virSecurityDomainRestoreNetdevLabel domainRestoreSecurityNetdevLabel; }; -virSecurityDriver *virSecurityDriverLookup(const char *name, - const char *virtDriver); +virSecurityDriver * +virSecurityDriverLookup(const char *name, + const char *virtDriver); --=20 2.50.0 From nobody Mon Sep 8 17:12:43 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=1753104194; cv=none; d=zohomail.com; s=zohoarc; b=XBVNz78rIWcf1fjsEKy10EyI99TMespRENvupcqmjuru5J2VrIeknX+YcEh3LIX+1tBuau8XN/FPNA7hk22nstbPcmIpdFkRA25yzRk7gtZdJdYsqbQXdU4oZ2pW1Zz2AttlbPV0TWRK9Q9kKcBTv2xvIN8BehynoOJBJf4/l10= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1753104194; 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=Fym5MGIawkiEHn5kfBOjmB40Gc9kZQQvdDSYWREWgxU=; b=Jx2dLsimXAxuwXvLEdGkmSMOX04FdCm89bp9excdu/wxSfC2mvA7M+LfE9yCq1H9gXveNSC/nVVtE72k7ofBKKzHBzuhK3ygzHMyTu9sj9yB+Y7eTDmBkGkksUNDnJRZjaMQzjmrGl+tu/I3nvJEsgjX3zDsoW3xAG/8aM4G2pU= 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 1753104194557786.0907618456725; Mon, 21 Jul 2025 06:23:14 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 9BA7214B3; Mon, 21 Jul 2025 09:23:13 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 5C9C0141E; Mon, 21 Jul 2025 09:21:24 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 25B7CE00; 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 7A8DFE00 for ; Mon, 21 Jul 2025 09:21:08 -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-247-fJCexPs6NxyY84qJoHlyog-1; Mon, 21 Jul 2025 09:21:06 -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 A236718004A7 for ; Mon, 21 Jul 2025 13:21:05 +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 E4530180035E for ; Mon, 21 Jul 2025 13:21:04 +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=1753104068; 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=+01V6AdxLSFkYush6KBj3GF7RP87AAR8Oq/HmOdeGxE=; b=M2UdHhToNdSy5bSdafDQH7U5I+ExhXfQfNdPXXyLcvMdBuYAvYkiM9oSlVH+zcPdixJ77w cBjkFuggOPkFCk0USCIDbtR95R+YQdKvE9go+HiY3IGzCtT+3lAHYjEqXkNVEfvRy60tRc pkrKbDQjnYvZ81gtA260n7U6exduOJw= X-MC-Unique: fJCexPs6NxyY84qJoHlyog-1 X-Mimecast-MFC-AGG-ID: fJCexPs6NxyY84qJoHlyog_1753104065 To: devel@lists.libvirt.org Subject: [PATCH 02/19] virSecuritySELinuxTransactionRun: Refactor cleanup Date: Mon, 21 Jul 2025 15:20:43 +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: XWvEqOtHYLcA9Fal9_QYV47ZFWD9oVvzr7sktuxiO1c_1753104065 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 3626RZJCV72RRBDPCLU7U6B6Z2SDKUPN X-Message-ID-Hash: 3626RZJCV72RRBDPCLU7U6B6Z2SDKUPN 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: 1753104195495116600 Content-Type: text/plain; charset="utf-8" From: Peter Krempa Automatically free 'paths' and remove temporary variable. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/security/security_selinux.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index 64e7f41ce0..0326073810 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -282,11 +282,10 @@ virSecuritySELinuxTransactionRun(pid_t pid G_GNUC_UNU= SED, { virSecuritySELinuxContextList *list =3D opaque; virSecurityManagerMetadataLockState *state; - const char **paths =3D NULL; + g_autofree const char **paths =3D NULL; size_t npaths =3D 0; size_t i; int rv; - int ret =3D -1; if (list->lock) { paths =3D g_new0(const char *, list->nItems); @@ -303,7 +302,7 @@ virSecuritySELinuxTransactionRun(pid_t pid G_GNUC_UNUSE= D, list->sharedFilesyste= ms, paths, npaths, list->lockMetadataExc= eption))) - goto cleanup; + return -1; for (i =3D 0; i < list->nItems; i++) { virSecuritySELinuxContextItem *item =3D list->items[i]; @@ -357,12 +356,9 @@ virSecuritySELinuxTransactionRun(pid_t pid G_GNUC_UNUS= ED, virSecurityManagerMetadataUnlock(list->manager, &state); if (rv < 0) - goto cleanup; + return -1; - ret =3D 0; - cleanup: - VIR_FREE(paths); - return ret; + return 0; } --=20 2.50.0 From nobody Mon Sep 8 17:12:43 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=1753104149; cv=none; d=zohomail.com; s=zohoarc; b=AZbNLrIUzxclrdlpOrSELSA3YRfmKprRrH8yBKczhjjoQloRmR6IS/+5j4oGqlox9Vne5xztaPzb4zdP88OUs2kDopRTxrzgZDr81/2mQAAluD6L41eIFL9C/o79FUUvm+wQljOgnS2rAEp0Jy8J5udim1Qzdcr16e+ZICoZEXg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1753104149; 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=liuT2Vq46g+Mas8avAYXtcevUtr9mklU0xbux3Tbze8=; b=SI8xc3lqUAMdfCnaHFfbfptUnud4NWkVB3KwNxzP0RTzHrZ2VXLmxU65scw8nOE+tipGAENHzIiWaRpR2DSG+4F31QxKpGCp7qaeXuEnOc8oU0ywC6vgugthP/pW2iC6HLlm2ZsjUYEsyNpkVAKMpFRoFV1OvB+2WnY6JQAZtOc= 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 1753104149354995.2275380177609; Mon, 21 Jul 2025 06:22:29 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 5BF0513FD; Mon, 21 Jul 2025 09:22:28 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id C170012D2; Mon, 21 Jul 2025 09:21:18 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 20827DF1; 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 A14F1E02 for ; Mon, 21 Jul 2025 09:21:09 -0400 (EDT) Received: from mx-prod-mc-01.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-25-r54CI8lQPHScA9w6GGbGlg-1; Mon, 21 Jul 2025 09:21:07 -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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CF4F5195FD06 for ; Mon, 21 Jul 2025 13:21:06 +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 1F2B2180035E for ; Mon, 21 Jul 2025 13:21:05 +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=1753104069; 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=x4V4SYYttqGidORPGNHGEVJoglobJ/g4j5nr357PEeI=; b=ZreAoYrsbAzGfqJMMLhiBA+fHihSRs0t+dskI2AojYXylDLK0hIelnUQ9gFivnnGuaSxhc Rvx+iDX6XYQIvfpmJujKonNnMWRtTIp4oAFZQcpjvsEKstKzJ0/+QLm90yzPEE9njNJL79 4FHCqABTtWcd9GG2iN1M157xfgvVUMQ= X-MC-Unique: r54CI8lQPHScA9w6GGbGlg-1 X-Mimecast-MFC-AGG-ID: r54CI8lQPHScA9w6GGbGlg_1753104066 To: devel@lists.libvirt.org Subject: [PATCH 03/19] virSecuritySELinuxMCSFind: Refactor variable clearing Date: Mon, 21 Jul 2025 15:20:44 +0200 Message-ID: <3bf23f3df5f3519bf0039f457b80605a559d8176.1753103831.git.pkrempa@redhat.com> 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: XSi26WswEr7TtAHZk8UEL4tQXXdpmYpwba21YXEyWOk_1753104066 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: TW55OEMQRHIPW7GGEBHY2XNPFD65PYBG X-Message-ID-Hash: TW55OEMQRHIPW7GGEBHY2XNPFD65PYBG 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: 1753104151124116600 Content-Type: text/plain; charset="utf-8" From: Peter Krempa Use automatic freeing for 'mcs' and adjust the code. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/security/security_selinux.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index 0326073810..28ac136635 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -398,7 +398,6 @@ virSecuritySELinuxMCSFind(virSecurityManager *mgr, { virSecuritySELinuxData *data =3D virSecurityManagerGetPrivateData(mgr); int catRange; - char *mcs =3D NULL; /* +1 since virRandomInt range is exclusive of the upper bound */ catRange =3D (catMax - catMin) + 1; @@ -416,6 +415,7 @@ virSecuritySELinuxMCSFind(virSecurityManager *mgr, for (;;) { int c1 =3D virRandomInt(catRange); int c2 =3D virRandomInt(catRange); + g_autofree char *mcs =3D NULL; VIR_DEBUG("Try cat %s:c%d,c%d", sens, c1 + catMin, c2 + catMin); @@ -439,12 +439,10 @@ virSecuritySELinuxMCSFind(virSecurityManager *mgr, } if (virHashLookup(data->mcs, mcs) =3D=3D NULL) - break; - - VIR_FREE(mcs); + return g_steal_pointer(&mcs); } - return mcs; + return NULL; } --=20 2.50.0 From nobody Mon Sep 8 17:12:43 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 Reviewed-by: J=C3=A1n Tomko --- 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 From nobody Mon Sep 8 17:12:43 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=1753104217; cv=none; d=zohomail.com; s=zohoarc; b=MV0yyHVcWYwUxO4oKcKhT9OIN9FU9SGfWa3960QjA7gqZ1rHrgOOD5VvMtjOrVhjUPDsJsrdxMebh6tHAzyd7jJiOuTy6vAO7tjiF2pOji89azuqSNIVVRmbVVaYb3tu0PnU7/JliVfk0Lj9ud1eiAfwVpiDhpdpBioiYPUnNvA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1753104217; 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=JUMI2e0AtdH/Q0KuV5k9gnsVRiQ9/dy0XmKhtOewKT4=; b=RDIVroliZ8KVPm5pTpax+bH9WK4VUYT3J272BoqkzvQqR4EhA/ZHNrTm1qgBw0kH3HSVZ/517f2BO048ctaHJgYimd0OVtK4f9orwGbCu3kMYlYQsGljYJb6EdnXohls66yRmzVixbAKo5hVmJ/ZIQXI2XGdXn5+idg4CVaNTpI= 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 1753104217458721.9861486083303; Mon, 21 Jul 2025 06:23:37 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 708491211; Mon, 21 Jul 2025 09:23:36 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 508ED12A9; Mon, 21 Jul 2025 09:21:26 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 7D4D1DF1; 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.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 0BA4CD4D for ; Mon, 21 Jul 2025 09:21:12 -0400 (EDT) Received: from mx-prod-mc-06.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-518-ikfsiJo0MMuS9vznBG-mJQ-1; Mon, 21 Jul 2025 09:21:10 -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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6C8691800282 for ; Mon, 21 Jul 2025 13:21:09 +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 B095418002B6 for ; Mon, 21 Jul 2025 13:21:08 +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=1753104071; 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=X1wVUYnwiauQqq3jMLZZRY9Bo9hNQ5zO60+67pO80yA=; b=MeymA4n0wtIwgnlkGICcZnRH67jjbhKEbrr1uIhv+hwf2gCCAuKiutidF+ahrv4uCZJ/Tb /8wTOh2wtoQY7S8e80kgsFYO7dkG8HZniZdm4dS1fetxZYHx2qCGoRRN0i4YeJSdmNg4KC G/JZf4Uc9GMDM8glTiRMi9zmcA91W34= X-MC-Unique: ikfsiJo0MMuS9vznBG-mJQ-1 X-Mimecast-MFC-AGG-ID: ikfsiJo0MMuS9vznBG-mJQ_1753104069 To: devel@lists.libvirt.org Subject: [PATCH 05/19] virSecuritySELinux(Set|Restore)TPMFileLabel: Automatically free 'cancel_path' Date: Mon, 21 Jul 2025 15:20:46 +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: 9GFIw8tThGoOaXN1YktoIV4l9JQ3cUZM19Rtb2MAqC0_1753104069 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 7LR2YI4HQ246MB5KHJ7WA7QZO2F7W7H4 X-Message-ID-Hash: 7LR2YI4HQ246MB5KHJ7WA7QZO2F7W7H4 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: 1753104219762116600 Content-Type: text/plain; charset="utf-8" From: Peter Krempa Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/security/security_selinux.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index 75ad5803a9..f042da4a13 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -1737,7 +1737,7 @@ virSecuritySELinuxSetTPMFileLabel(virSecurityManager = *mgr, { int rc; virSecurityLabelDef *seclabel; - char *cancel_path; + g_autofree char *cancel_path =3D NULL; const char *tpmdev; seclabel =3D virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX_NAM= E); @@ -1755,7 +1755,6 @@ virSecuritySELinuxSetTPMFileLabel(virSecurityManager = *mgr, rc =3D virSecuritySELinuxSetFilecon(mgr, cancel_path, seclabel->imagelabel, false); - VIR_FREE(cancel_path); if (rc < 0) { virSecuritySELinuxRestoreTPMFileLabelInt(mgr, def, tpm); return -1; @@ -1786,7 +1785,7 @@ virSecuritySELinuxRestoreTPMFileLabelInt(virSecurityM= anager *mgr, { int rc =3D 0; virSecurityLabelDef *seclabel; - char *cancel_path; + g_autofree char *cancel_path =3D NULL; const char *tpmdev; seclabel =3D virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX_NAM= E); @@ -1801,7 +1800,6 @@ virSecuritySELinuxRestoreTPMFileLabelInt(virSecurityM= anager *mgr, if ((cancel_path =3D virTPMCreateCancelPath(tpmdev)) !=3D NULL) { if (virSecuritySELinuxRestoreFileLabel(mgr, cancel_path, false= ) < 0) rc =3D -1; - VIR_FREE(cancel_path); } break; case VIR_DOMAIN_TPM_TYPE_EMULATOR: --=20 2.50.0 From nobody Mon Sep 8 17:12:43 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=1753104238; cv=none; d=zohomail.com; s=zohoarc; b=Nko6dYTbc4OFe7rVyJxPelC/2EY8oKy0T4QwcCt9FG/Cq9xSj6EPNucnP3wu9U6FkXbRKQ024v2BJWZocX09iQtHBZHMg2iHpdofUP+YAtVbyxAz5SelKu0JnXpvMiDw2WVRh+EJfbNQl4P1PF33DSXr5Wfyij9bnLdPtsXlhVc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1753104238; 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=DCI6PVV3txAbCU7e7WO2Cmr9zBfw8HZmdf9yWNaCPak=; b=gsmkjEGNLCgqu9KpBhYFXygc1/0YJeBeeQ8C52mKbOVbs37iRV0htNxu0JbfBxDy7toOqxxIgABPs9Jr9fcfPZgmT733lAU2LbW7S8SHPomWpkghh99zXxwxIRZ0V/Q/H5Mve6q4xYsF5uhBJ8eEZTWBFtOw3XieILyZsQBDZaQ= 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 1753104238357253.82397863152949; Mon, 21 Jul 2025 06:23:58 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 597FD1448; Mon, 21 Jul 2025 09:23:57 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 0B045143C; Mon, 21 Jul 2025 09:21:29 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 4B525C67; Mon, 21 Jul 2025 09:21:14 -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 195C1D4D for ; Mon, 21 Jul 2025 09:21:13 -0400 (EDT) Received: from mx-prod-mc-06.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-589-Vl-zvqXBMqWoaosajEK2DA-1; Mon, 21 Jul 2025 09:21:11 -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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9DDF81800165 for ; Mon, 21 Jul 2025 13:21:10 +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 DC9B8180035E for ; Mon, 21 Jul 2025 13:21:09 +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=1753104072; 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=rYftmtUY0iQ1eJzyu+ZkmOSd5hu9Qrob2kzUBTrTFvQ=; b=N5Ha7Ig7j6S+w6LYEGUF1z19BDr6Bhn7+SvGOGXmD7pBBdc0n44UFATdQrjbOH7NaNrCt8 3Aaj4ZlYkvhxJ2kTHCxcqab+uicAMWA9cETQeto+S9QdYPZmolZJMz0htERAhBHHllAY39 Fwn87uREXgGsMy7vfirKZ2MTCo4ygt4= X-MC-Unique: Vl-zvqXBMqWoaosajEK2DA-1 X-Mimecast-MFC-AGG-ID: Vl-zvqXBMqWoaosajEK2DA_1753104070 To: devel@lists.libvirt.org Subject: [PATCH 06/19] virSecuritySELinuxRestoreFileLabels: Refactor variable freeing Date: Mon, 21 Jul 2025 15:20:47 +0200 Message-ID: <2193e7a1f19960e448f22e48aa2a8912d9526d10.1753103831.git.pkrempa@redhat.com> 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: l34swsQyPfju6ZgJ0sdtm3dM-zFug9tqzRKarUiRLkA_1753104070 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 4OUROQTVMSXUOCS5QQ6RIOFTK6QZAKGJ X-Message-ID-Hash: 4OUROQTVMSXUOCS5QQ6RIOFTK6QZAKGJ 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: 1753104240129116600 Content-Type: text/plain; charset="utf-8" From: Peter Krempa Declare 'filename' inside the loop that is using it and use automatic freeing. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/security/security_selinux.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index f042da4a13..854e46954e 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -3698,7 +3698,6 @@ virSecuritySELinuxRestoreFileLabels(virSecurityManage= r *mgr, { int ret =3D 0; struct dirent *ent; - char *filename =3D NULL; g_autoptr(DIR) dir =3D NULL; if ((ret =3D virSecuritySELinuxRestoreFileLabel(mgr, path, true))) @@ -3711,9 +3710,8 @@ virSecuritySELinuxRestoreFileLabels(virSecurityManage= r *mgr, return -1; while ((ret =3D virDirRead(dir, &ent, path)) > 0) { - filename =3D g_strdup_printf("%s/%s", path, ent->d_name); + g_autofree char *filename =3D g_strdup_printf("%s/%s", path, ent->= d_name); ret =3D virSecuritySELinuxRestoreFileLabel(mgr, filename, true); - VIR_FREE(filename); if (ret < 0) break; } --=20 2.50.0 From nobody Mon Sep 8 17:12:43 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=1753104267; cv=none; d=zohomail.com; s=zohoarc; b=P2McJrKvqVhT4IyQO6LhJnqinaoG7UgzKxt+8rBwOPqxxRiXhjK28gaS0SmCeqlGORlPmuq04lCg3QqYHRsEG13lMgkB7gtqMdEfSnCa/rlQ52aqA56jDbcl1KVtlX9CuXb7kKkN6/Z7qahc8S0PU+MwcLp2pm/Md/xhzP5bGMk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1753104267; 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=2kiVHj/0mFJnD1QbYblVdfvhckKgtyym9xE0zvduGrM=; b=njgFrZwxvtFA3JaoJpkil65RS8nGADlkTGSYAFxlPjDze6Xj0jk86K4UEnbQRIWAwZ0xd6Wx4NhPm41usAQsrSuWGS3uFgx8nRNlrrtWI3U0kK/fDQ1WC1oCdlJ3hDdLpD4cKom8PWw3TTgmfREy8SXYFsASRIJVocQvwmNRtLQ= 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 1753104267165866.0485876440653; Mon, 21 Jul 2025 06:24:27 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 228E19D2; Mon, 21 Jul 2025 09:24:26 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 355D1146B; Mon, 21 Jul 2025 09:21:32 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id BE48410F2; Mon, 21 Jul 2025 09:21:14 -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 400E4DF2 for ; Mon, 21 Jul 2025 09:21:14 -0400 (EDT) Received: from mx-prod-mc-06.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-657-Bj1MJ3LJPh69cawIYpAo-Q-1; Mon, 21 Jul 2025 09:21:12 -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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CD7AC1800281 for ; Mon, 21 Jul 2025 13:21:11 +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 23A9618002B6 for ; Mon, 21 Jul 2025 13:21:10 +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=1753104074; 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=aqgERgi8b80ilY+QxZcgkySriDgNFKNtJlywyvp75m0=; b=Zbm2w4F2F74DMTQXo9hS6KUrLjrhDLI0Vty8NXYerv6rXs9sjzsbi7BnOwKvAS4hh16PI8 hngSL9srnbiWjcGY2F+lv5KQm8KR9FDvMkJ9Pra0Jt64tiFatk6MgjZ4nH1fZk8JhZfpY4 2oLKxkh7ylevnpy0hUO5xknCBnrmu04= X-MC-Unique: Bj1MJ3LJPh69cawIYpAo-Q-1 X-Mimecast-MFC-AGG-ID: Bj1MJ3LJPh69cawIYpAo-Q_1753104071 To: devel@lists.libvirt.org Subject: [PATCH 07/19] virSecuritySELinux(Set|Restore)HostdevCapsLabel: Refactor cleanup Date: Mon, 21 Jul 2025 15:20:48 +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: 4_H2OiSe7MXIRRVC2xNjiRqGqyBx7Sasgdx07BUdhCE_1753104071 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: NGEZBFTKZ4T6EDAZFS2RGJSY6RU7LY3K X-Message-ID-Hash: NGEZBFTKZ4T6EDAZFS2RGJSY6RU7LY3K 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: 1753104268379116600 Content-Type: text/plain; charset="utf-8" From: Peter Krempa Declare 'path' only in blocks where it's used and autofree it. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/security/security_selinux.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index 854e46954e..2cdc6bf954 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -2333,7 +2333,6 @@ virSecuritySELinuxSetHostdevCapsLabel(virSecurityMana= ger *mgr, { int ret =3D -1; virSecurityLabelDef *secdef; - char *path; secdef =3D virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX_NAME); if (secdef =3D=3D NULL) @@ -2341,6 +2340,7 @@ virSecuritySELinuxSetHostdevCapsLabel(virSecurityMana= ger *mgr, switch (dev->source.caps.type) { case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_STORAGE: { + g_autofree char *path =3D NULL; if (vroot) { path =3D g_strdup_printf("%s/%s", vroot, dev->source.caps.u.storage.block); @@ -2348,11 +2348,11 @@ virSecuritySELinuxSetHostdevCapsLabel(virSecurityMa= nager *mgr, path =3D g_strdup(dev->source.caps.u.storage.block); } ret =3D virSecuritySELinuxSetFilecon(mgr, path, secdef->imagelabel= , true); - VIR_FREE(path); break; } case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_MISC: { + g_autofree char *path =3D NULL; if (vroot) { path =3D g_strdup_printf("%s/%s", vroot, dev->source.caps.u.misc.chardev); @@ -2360,7 +2360,6 @@ virSecuritySELinuxSetHostdevCapsLabel(virSecurityMana= ger *mgr, path =3D g_strdup(dev->source.caps.u.misc.chardev); } ret =3D virSecuritySELinuxSetFilecon(mgr, path, secdef->imagelabel= , true); - VIR_FREE(path); break; } @@ -2562,10 +2561,10 @@ virSecuritySELinuxRestoreHostdevCapsLabel(virSecuri= tyManager *mgr, const char *vroot) { int ret =3D -1; - char *path; switch (dev->source.caps.type) { case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_STORAGE: { + g_autofree char *path =3D NULL; if (vroot) { path =3D g_strdup_printf("%s/%s", vroot, dev->source.caps.u.storage.block); @@ -2573,11 +2572,11 @@ virSecuritySELinuxRestoreHostdevCapsLabel(virSecuri= tyManager *mgr, path =3D g_strdup(dev->source.caps.u.storage.block); } ret =3D virSecuritySELinuxRestoreFileLabel(mgr, path, true); - VIR_FREE(path); break; } case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_MISC: { + g_autofree char *path =3D NULL; if (vroot) { path =3D g_strdup_printf("%s/%s", vroot, dev->source.caps.u.misc.chardev); @@ -2585,7 +2584,6 @@ virSecuritySELinuxRestoreHostdevCapsLabel(virSecurity= Manager *mgr, path =3D g_strdup(dev->source.caps.u.misc.chardev); } ret =3D virSecuritySELinuxRestoreFileLabel(mgr, path, true); - VIR_FREE(path); break; } --=20 2.50.0 From nobody Mon Sep 8 17:12:43 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=1753104293; cv=none; d=zohomail.com; s=zohoarc; b=kA05J2xvNjHkvohkaNnwzt+7MRASFZV1gYE5BoPbVu3mVSrNhN04wa8ijMEsGYfEawzspnzbHmwvjE8TS1hd5yNGRDY46D19PC3YLSdf6wGahz2TLJVYDqji27wVR16JEkHRPCdZZk1lxMUzkcfMz+GJqvwp7MJa8Ku2PrRvVRI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1753104293; 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=pJcMYVvi5Ybb3yfrhQtMPRxaJs0BSkKNeTaf8ePn4rQ=; b=cWVuyoMwc5Y17gAEK6RVfRSXkJ2prIbPF234Fd0c1AGDDTWhfupRw6VkuaCca1hrpetgU5rBm8ByDQvif59rfEcbUuFVC9DKETG/3is4dCABgpQ2JeV9m0B8EtvAAXHTsMfzKwjkMmIeLzZ0vguCJbwBKFdhFrZvKF/RWwA3Ujo= 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 1753104293922445.48554352563553; Mon, 21 Jul 2025 06:24:53 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id E4E531482; Mon, 21 Jul 2025 09:24:52 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 27C3E110C; Mon, 21 Jul 2025 09:21:35 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id CF024E78; Mon, 21 Jul 2025 09:21:27 -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 0F19312C1 for ; Mon, 21 Jul 2025 09:21:17 -0400 (EDT) Received: from mx-prod-mc-06.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-80-jawFtuRnOJel06TmQok7fg-1; Mon, 21 Jul 2025 09:21:14 -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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 115621800282 for ; Mon, 21 Jul 2025 13:21:13 +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 4FE8E18002B6 for ; Mon, 21 Jul 2025 13:21:12 +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=1753104076; 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=uZuKuDPWG/4gXLxuqsBXq3GNSIQZJzJjqRhSMJjGi9k=; b=ipNnk8q/6Q9LOoA1lSbFkrPBMGlvrMY7ww8IER4ynEM/wnVJgygPaoLgBtpLtEWitShi1K amMWmKQAM78UMj1/ka6cbubdzp82vDdKYUR0O4WTsE/jwGIyEvG61cuU1t2qrN55Kigr3N /w21axTlx2T7kKa/oa8Uu9Uabgve2vM= X-MC-Unique: jawFtuRnOJel06TmQok7fg-1 X-Mimecast-MFC-AGG-ID: jawFtuRnOJel06TmQok7fg_1753104073 To: devel@lists.libvirt.org Subject: [PATCH 08/19] virSecuritySELinux(Set|Restore)ChardevLabel: Refactor cleanup Date: Mon, 21 Jul 2025 15:20:49 +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: SK11Sn09KUmmnCQp8_nNZOyVQArWoMAnPql0mkabPWo_1753104073 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: FS3OXNOHDYRJ2TQ7OQAYUFWLTHR4NTP3 X-Message-ID-Hash: FS3OXNOHDYRJ2TQ7OQAYUFWLTHR4NTP3 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: 1753104295254116600 Content-Type: text/plain; charset="utf-8" From: Peter Krempa Declare 'in'/'out' only in the bocks which use them and automatically free them. Since cleanup section was removed we don't need a 'ret' variable any more. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/security/security_selinux.c | 87 +++++++++++++++------------------ 1 file changed, 40 insertions(+), 47 deletions(-) diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index 2cdc6bf954..25f0c45955 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -2667,8 +2667,6 @@ virSecuritySELinuxSetChardevLabel(virSecurityManager = *mgr, virSecurityLabelDef *seclabel; virSecurityDeviceLabelDef *chr_seclabel =3D NULL; char *imagelabel =3D NULL; - char *in =3D NULL, *out =3D NULL; - int ret =3D -1; seclabel =3D virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX_NAM= E); if (!seclabel || !seclabel->relabel) @@ -2693,10 +2691,12 @@ virSecuritySELinuxSetChardevLabel(virSecurityManage= r *mgr, switch (dev_source->type) { case VIR_DOMAIN_CHR_TYPE_DEV: case VIR_DOMAIN_CHR_TYPE_FILE: - ret =3D virSecuritySELinuxSetFilecon(mgr, - dev_source->data.file.path, - imagelabel, - true); + if (virSecuritySELinuxSetFilecon(mgr, + dev_source->data.file.path, + imagelabel, + true) < 0) + return -1; + break; case VIR_DOMAIN_CHR_TYPE_UNIX: @@ -2710,37 +2710,35 @@ virSecuritySELinuxSetChardevLabel(virSecurityManage= r *mgr, dev_source->data.nix.path, imagelabel, true) < 0) - goto done; + return -1; } - ret =3D 0; + break; - case VIR_DOMAIN_CHR_TYPE_PIPE: - in =3D g_strdup_printf("%s.in", dev_source->data.file.path); - out =3D g_strdup_printf("%s.out", dev_source->data.file.path); + case VIR_DOMAIN_CHR_TYPE_PIPE: { + g_autofree char *in =3D g_strdup_printf("%s.in", dev_source->data.= file.path); + g_autofree char *out =3D g_strdup_printf("%s.out", dev_source->dat= a.file.path); if (virFileExists(in) && virFileExists(out)) { if ((virSecuritySELinuxSetFilecon(mgr, in, imagelabel, true) <= 0) || - (virSecuritySELinuxSetFilecon(mgr, out, imagelabel, true) = < 0)) { - goto done; - } - } else if (virSecuritySELinuxSetFilecon(mgr, - dev_source->data.file.path, - imagelabel, - true) < 0) { - goto done; + (virSecuritySELinuxSetFilecon(mgr, out, imagelabel, true) = < 0)) + return -1; + + } else { + if (virSecuritySELinuxSetFilecon(mgr, + dev_source->data.file.path, + imagelabel, + true) < 0) + return -1; } - ret =3D 0; + break; + } default: - ret =3D 0; break; } - done: - VIR_FREE(in); - VIR_FREE(out); - return ret; + return 0; } static int @@ -2752,8 +2750,6 @@ virSecuritySELinuxRestoreChardevLabel(virSecurityMana= ger *mgr, { virSecurityLabelDef *seclabel; virSecurityDeviceLabelDef *chr_seclabel =3D NULL; - char *in =3D NULL, *out =3D NULL; - int ret =3D -1; seclabel =3D virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX_NAM= E); if (!seclabel || !seclabel->relabel) @@ -2775,8 +2771,8 @@ virSecuritySELinuxRestoreChardevLabel(virSecurityMana= ger *mgr, if (virSecuritySELinuxRestoreFileLabel(mgr, dev_source->data.file.path, true) < 0) - goto done; - ret =3D 0; + return -1; + break; case VIR_DOMAIN_CHR_TYPE_UNIX: @@ -2784,36 +2780,33 @@ virSecuritySELinuxRestoreChardevLabel(virSecurityMa= nager *mgr, if (virSecuritySELinuxRestoreFileLabel(mgr, dev_source->data.nix.pa= th, true) < 0) - goto done; + return -1; } - ret =3D 0; + break; - case VIR_DOMAIN_CHR_TYPE_PIPE: - out =3D g_strdup_printf("%s.out", dev_source->data.file.path); - in =3D g_strdup_printf("%s.in", dev_source->data.file.path); + case VIR_DOMAIN_CHR_TYPE_PIPE: { + g_autofree char *out =3D g_strdup_printf("%s.out", dev_source->dat= a.file.path); + g_autofree char *in =3D g_strdup_printf("%s.in", dev_source->data.= file.path); if (virFileExists(in) && virFileExists(out)) { if ((virSecuritySELinuxRestoreFileLabel(mgr, out, true) < 0) || - (virSecuritySELinuxRestoreFileLabel(mgr, in, true) < 0)) { - goto done; - } - } else if (virSecuritySELinuxRestoreFileLabel(mgr, - dev_source->data.fil= e.path, - true) < 0) { - goto done; + (virSecuritySELinuxRestoreFileLabel(mgr, in, true) < 0)) + return -1; + + } else { + if (virSecuritySELinuxRestoreFileLabel(mgr, + dev_source->data.file.p= ath, + true) < 0) + return -1; } - ret =3D 0; + } break; default: - ret =3D 0; break; } - done: - VIR_FREE(in); - VIR_FREE(out); - return ret; + return 0; } --=20 2.50.0 From nobody Mon Sep 8 17:12:43 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=1753104316; cv=none; d=zohomail.com; s=zohoarc; b=Oxt7N55YqqxP7FLKbplyKIFfMOiEer2Zld2Gf3Ymwxrpe/nGfqNowlxOLAREtJtTSBAwEwIDuTOT2KHczVLbtyHW3GSr2hF1My1JWDAPNvn0jQ0ksh9xnotipTwwNEiXFF/bpAqm/fQWfoc1nNbi5jYc6nYGT7CwjPHnK+HwF+Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1753104316; 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=yjedDmiCOtYsmrhrNCV23Id2kZKjUHCO4LS4dqqlF3k=; b=aFFsKuzCzQgU/3bsSiG4Ug4T7YWVmSyMxjye+niSeQjcSEy599/tKtPpnTw4K+RgnLrl4jz4WL3MmEsyyqYnogHVZNDrZSzmN3NzOeNXXGqb99BIZ+G0hmZdcYM9ZFgR9Bk1FdM1eWBc+OBKzL4IIMoJuNUpgebFHKB29oi+Dmg= 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 1753104316932299.4701934760744; Mon, 21 Jul 2025 06:25:16 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id D1617C15; Mon, 21 Jul 2025 09:25:15 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 26C1712B8; Mon, 21 Jul 2025 09:21:38 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id B624F11B1; Mon, 21 Jul 2025 09:21:33 -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 60D511324 for ; Mon, 21 Jul 2025 09:21:17 -0400 (EDT) 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-128-7dXOgc51MRGGcU5xHBZ9XQ-1; Mon, 21 Jul 2025 09:21:15 -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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7F71B19560A3 for ; Mon, 21 Jul 2025 13:21:14 +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 7EBD218002B6 for ; Mon, 21 Jul 2025 13:21:13 +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=1753104076; 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=EOJ8nLutnkHx05DX9r/v/S6X9d+7iMQlPGGOtI/IQt4=; b=FqZnhQhM9rXEdoa8pTa+eVGvj9vHY0lAnn3g3kLuvDDpj0xLZdKo002zXV9pzw7Z9zsSek sZFWLX37BTHrX3Gi3ouR4Sb+XrD41qKmdHFJPBeZZibMeXS9dS5Fpz9lZh2XWDZ60Vt5lJ UTL901WTnHcvin/wzYnD+w4tOMGBjE8= X-MC-Unique: 7dXOgc51MRGGcU5xHBZ9XQ-1 X-Mimecast-MFC-AGG-ID: 7dXOgc51MRGGcU5xHBZ9XQ_1753104074 To: devel@lists.libvirt.org Subject: [PATCH 09/19] virSecuritySELinuxSet(Daemon)SocketLabel: Refactor cleanup Date: Mon, 21 Jul 2025 15:20:50 +0200 Message-ID: <4cb8efb048ef3c3471aaf445c85a846f9d4bbfc8.1753103831.git.pkrempa@redhat.com> 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: KvSfXXSh8nvpUnaVzdfFE7oiWQ1FRIjfBETVfO3FQb8_1753104074 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: LM5NW4XVEC7QASP724BDEMBROPNQNKUC X-Message-ID-Hash: LM5NW4XVEC7QASP724BDEMBROPNQNKUC 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: 1753104318918116600 Content-Type: text/plain; charset="utf-8" From: Peter Krempa Automatically free temporary variables and change 'cleanup' label to 'error'. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/security/security_selinux.c | 37 +++++++++++++++------------------ 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index 25f0c45955..ad789c611f 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -3147,9 +3147,8 @@ virSecuritySELinuxSetDaemonSocketLabel(virSecurityMan= ager *mgr G_GNUC_UNUSED, { /* TODO: verify DOI */ virSecurityLabelDef *secdef; - char *scon =3D NULL; - char *str =3D NULL; - int rc =3D -1; + g_autofree char *scon =3D NULL; + g_autofree char *str =3D NULL; secdef =3D virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX_NAME); if (!secdef || !secdef->label) @@ -3159,34 +3158,33 @@ virSecuritySELinuxSetDaemonSocketLabel(virSecurityM= anager *mgr G_GNUC_UNUSED, virReportError(VIR_ERR_INTERNAL_ERROR, _("security label driver mismatch: '%1$s' model con= figured for domain, but hypervisor driver is '%2$s'."), secdef->model, SECURITY_SELINUX_NAME); - goto done; + goto error; } if (getcon_raw(&scon) =3D=3D -1) { virReportSystemError(errno, _("unable to get current process context '%1$= s'"), secdef->label); - goto done; + goto error; } if (!(str =3D virSecuritySELinuxContextAddRange(secdef->label, scon))) - goto done; + goto error; VIR_DEBUG("Setting VM %s socket context %s", def->name, str); if (setsockcreatecon_raw(str) =3D=3D -1) { virReportSystemError(errno, _("unable to set socket security context '%1$= s'"), str); - goto done; + goto error; } - rc =3D 0; - done: + return 0; + error: if (security_getenforce() !=3D 1) - rc =3D 0; - freecon(scon); - VIR_FREE(str); - return rc; + return 0; + + return -1; } static int @@ -3194,7 +3192,6 @@ virSecuritySELinuxSetSocketLabel(virSecurityManager *= mgr G_GNUC_UNUSED, virDomainDef *vm) { virSecurityLabelDef *secdef; - int rc =3D -1; secdef =3D virDomainDefGetSecurityLabelDef(vm, SECURITY_SELINUX_NAME); if (!secdef || !secdef->label) @@ -3204,7 +3201,7 @@ virSecuritySELinuxSetSocketLabel(virSecurityManager *= mgr G_GNUC_UNUSED, virReportError(VIR_ERR_INTERNAL_ERROR, _("security label driver mismatch: '%1$s' model con= figured for domain, but hypervisor driver is '%2$s'."), secdef->model, SECURITY_SELINUX_NAME); - goto done; + goto error; } VIR_DEBUG("Setting VM %s socket context %s", @@ -3213,16 +3210,16 @@ virSecuritySELinuxSetSocketLabel(virSecurityManager= *mgr G_GNUC_UNUSED, virReportSystemError(errno, _("unable to set socket security context '%1$= s'"), secdef->label); - goto done; + goto error; } - rc =3D 0; + return 0; - done: + error: if (security_getenforce() !=3D 1) - rc =3D 0; + return 0; - return rc; + return -1; } static int --=20 2.50.0 From nobody Mon Sep 8 17:12:43 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 Reviewed-by: J=C3=A1n Tomko --- 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 From nobody Mon Sep 8 17:12:43 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=1753104363; cv=none; d=zohomail.com; s=zohoarc; b=MAQSzeAeu0FQRnWy3zTN7w8tW1p9g9Lw26H6by99wPjo2Gu0Q+17CGhoOKi4BZ2Wd5eRFc44j+rebb9ex+QRBC53Q1DoV+srpifcAn2JrLF+fnvB7Ped49B2C7Gc8Jm8A2tyUj2YI0o5b4colldNfldPQSgLS8NymQDCFI3+7cU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1753104363; 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=GFsljvoCEP+gViRxxwIUSv4znSIqeTCiJ+GpPUSICxw=; b=lw4xmwneSEMH/4pdEkfmHwcu5470sL+DPVAqw5gwBWBPy6n0XsNAf7yC2guk9xWhknLt/AREbCluAIAvnN9DsuBvYZ0OxDeZ2IPdi6Q6dTAHA2AhYe8H/I2tH2W2HkI9VhwAA6Ew7Ui115xoJZTadWr8pNFc8JOnWAta/+nHJ7w= 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 1753104363421622.6723803681699; Mon, 21 Jul 2025 06:26:03 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 4C3171293; Mon, 21 Jul 2025 09:26:02 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 5735C14B9; Mon, 21 Jul 2025 09:21:44 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 0CB25DF2; Mon, 21 Jul 2025 09:21:35 -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 96619110C for ; Mon, 21 Jul 2025 09:21:19 -0400 (EDT) Received: from mx-prod-mc-06.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-587-lSiWF8u7N9KSmMneW0DTHA-1; Mon, 21 Jul 2025 09:21:17 -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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 975641800282 for ; Mon, 21 Jul 2025 13:21:16 +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 CE858180035E for ; Mon, 21 Jul 2025 13:21:15 +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=1753104079; 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=nurd4MThGpwc/comVxD+Ite2VwV0aUK35KR2CSZJdSg=; b=Wpv4pxY2+a8m0PBQIi597MFzfUopijfKJkJM3TuNsQsGydOnEUEpcLDqx7GT2oL7ZXl4V6 yeCRLIlhG4lRe7OF7wfjEdGhnVkUPmtJMly186KLQA+I5NRpsg0kpk2LMqnA1K9jdM7Yww teBRcZFwpxqGNiJezw3wJFoe2V0eiD8= X-MC-Unique: lSiWF8u7N9KSmMneW0DTHA-1 X-Mimecast-MFC-AGG-ID: lSiWF8u7N9KSmMneW0DTHA_1753104076 To: devel@lists.libvirt.org Subject: [PATCH 11/19] security_selinux: Declare internal autoptr cleanup helper for 'context_t' Date: Mon, 21 Jul 2025 15:20:52 +0200 Message-ID: <5ace1cc6b00e01b578f442ba27a7403c02ef327f.1753103831.git.pkrempa@redhat.com> 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: S0WEMctFc92U9mC4X7ax-Hl8dXQ0VUQrm9BuiBiEnHQ_1753104076 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: E6QM2C2I5NPYZD3OGOLMAHJRZTG52Y54 X-Message-ID-Hash: E6QM2C2I5NPYZD3OGOLMAHJRZTG52Y54 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: 1753104365332116600 Content-Type: text/plain; charset="utf-8" From: Peter Krempa The selinux headers have a 'typedef context_s_t *context_t;' definition in the header so we declare autoptr cleanup function for 'context_s_t' and use it instead of 'context_t' definitions. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/security/security_selinux.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index f01a707c28..87348f36fa 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -48,6 +48,9 @@ VIR_LOG_INIT("security.security_selinux"); #define MAX_CONTEXT 1024 +/* selinux headers define 'context_t' as pointer to 'context_s_t' */ +G_DEFINE_AUTOPTR_CLEANUP_FUNC(context_s_t, context_free); + typedef struct _virSecuritySELinuxData virSecuritySELinuxData; struct _virSecuritySELinuxData { char *domain_context; --=20 2.50.0 From nobody Mon Sep 8 17:12:43 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=1753104383; cv=none; d=zohomail.com; s=zohoarc; b=nGd9gd5j1jIb4OQ+C1eEIwBhCP0TXibZNQiLNs+LYxev6f3qPE33cha/UsKiIGo0+81bd9cvGuPskVJuZRq8MhHmAIksHFCmctp1yXJPZXBzL+kPsCRQ+aHxGjVjpgM3dzifLhvNG/lNS5EJUyL5kNfYFr1DwCOpOXeRlMT+BSQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1753104383; 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=YHWdrxhbqzR7G534HgyjQxvnd+MsxMq48LchEsEku+A=; b=d/e7UXhTPgXBS2NWlNgu7d37kTDmqqcgEVO8A/6UxKj8lJGjOQsvvSdlIGcL5OPFgxwQk+i7WqmDZEzzRBt1TnX3opN3+xlsft+XfpqaP9YulLVKMX5DsNQpNaw2ZFjD72dMwuqY18Y9CRZ+qqNA7XFgMHYJyepE0AzM9DYrc7M= 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 1753104383249166.18398893722906; Mon, 21 Jul 2025 06:26:23 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 51981143B; Mon, 21 Jul 2025 09:26:22 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 3C94B11F4; Mon, 21 Jul 2025 09:21:46 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id D359911A8; Mon, 21 Jul 2025 09:21:38 -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 58EE811A8 for ; Mon, 21 Jul 2025 09:21:20 -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-314-O0jMAJRwN_2-c2wqfbhv9g-1; Mon, 21 Jul 2025 09:21:18 -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 CD9D018001F7 for ; Mon, 21 Jul 2025 13:21:17 +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 1AE59180035E for ; Mon, 21 Jul 2025 13:21:16 +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=1753104080; 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=Ij68HOqfxNJIuSAVX9JqXrYndeWgpuITzXNUO13fHXw=; b=WH5MJfiUsl7pwNon6UualuctcvpEyWWq3hotimSt/449FO5G+4SCVItCevmv5w81nvDySm so/mXNa6HIX+Xv5YLqP4lsFTw6ZHF2Kv+PBSTXrIouzVkqB/qPtZkgifJlP8VnH/xsBOCP xFf+Nsl0GHiDdKIKbpZK/PM/AFt9E8s= X-MC-Unique: O0jMAJRwN_2-c2wqfbhv9g-1 X-Mimecast-MFC-AGG-ID: O0jMAJRwN_2-c2wqfbhv9g_1753104077 To: devel@lists.libvirt.org Subject: [PATCH 12/19] virSecuritySELinuxContextAddRange: Refactor cleanup of 'context_t' Date: Mon, 21 Jul 2025 15:20:53 +0200 Message-ID: <2024a71eb89bb8c99787745fba599e495066bdd4.1753103831.git.pkrempa@redhat.com> 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: JNt4lp58TlK9fyqkk7puficZP84esObh0DaxWzloRs4_1753104077 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: JIJH4Y4GHOGXDSSZXDYDVJYPI6VZQLDS X-Message-ID-Hash: JIJH4Y4GHOGXDSSZXDYDVJYPI6VZQLDS 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: 1753104385512116600 Content-Type: text/plain; charset="utf-8" From: Peter Krempa Use the new autoptr helper to free the temporary variables and refactor cleanup. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/security/security_selinux.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index 87348f36fa..55a5593fa5 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -572,37 +572,31 @@ virSecuritySELinuxContextAddRange(const char *src, const char *dst) { const char *str =3D NULL; - char *ret =3D NULL; - context_t srccon =3D NULL; - context_t dstcon =3D NULL; + g_autoptr(context_s_t) srccon =3D NULL; + g_autoptr(context_s_t) dstcon =3D NULL; if (!src || !dst) - return ret; + return NULL; if (!(srccon =3D context_new(src)) || !(dstcon =3D context_new(dst))) { virReportSystemError(errno, "%s", _("unable to allocate security context")); - goto cleanup; + return NULL; } if (context_range_set(dstcon, context_range_get(srccon)) =3D=3D -1) { virReportSystemError(errno, _("unable to set security context range '%1$s= '"), dst); - goto cleanup; + return NULL; } if (!(str =3D context_str(dstcon))) { virReportSystemError(errno, "%s", _("Unable to format SELinux context")); - goto cleanup; + return NULL; } - ret =3D g_strdup(str); - - cleanup: - if (srccon) context_free(srccon); - if (dstcon) context_free(dstcon); - return ret; + return g_strdup(str); } --=20 2.50.0 From nobody Mon Sep 8 17:12:43 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=1753104403; cv=none; d=zohomail.com; s=zohoarc; b=fmi2jO2U0pzEQeyBHpXjKsAZ6PxEINNeTZ5ickk8h5IVPjq9r5QgAbZb+6eD3VQLAzMKGaXOW4hwNmaKy40uIf0AqlMxNrxzsffo2z1EFOiBFmtxpfbCkpVN9vh+qNMy0SsAGyok9dKjm5ApFubkB4wsyL6CTLwvhIBXJAAqW/A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1753104403; 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=tSLLjy2rvwf+60LZpupw22RlHv+aYIqyVp2yhATueew=; b=U0vwdtk37417OVfWf+Z5mie2H3e9+MlOdJOBpkmjhRmj11ZPufXczejd2VEUnu5PTKK/5aPxfBlCn1JnFt0G2jPoxJOYI41gAhgfHgj9j/akZDe7Lh0ev6D04eS6DiSQ1PrmuA6xS7oXq4HueBw0mD3I4bU9tXywiXWDuAp/tgg= 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 17531044038251007.8682355297125; Mon, 21 Jul 2025 06:26:43 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id C2C3214C7; Mon, 21 Jul 2025 09:26:42 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 6B9FF12F8; Mon, 21 Jul 2025 09:21:50 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id D2C9EE5A; Mon, 21 Jul 2025 09:21:44 -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 50A431406 for ; Mon, 21 Jul 2025 09:21:22 -0400 (EDT) Received: from mx-prod-mc-06.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-131-8ra6ExuaM-iJe1gq5qtjjw-1; Mon, 21 Jul 2025 09:21:19 -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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 04FA918009CA for ; Mon, 21 Jul 2025 13:21:19 +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 47543180035E for ; Mon, 21 Jul 2025 13:21:18 +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=1753104082; 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=Vbyj9Jw6iVF+C7urM+SZgxiFYeUOS1eCzh6c5c7LILo=; b=jRPlnSHIKAoxjSnuAHnE81/CaV3gxm4Nc2HgZLPC8r44AwCxJJxmGEDj8rDuT4fxQh/dVC gZ99nSLCmR0S5wDhVkX3m6AhPro2QInSqV9GzvUS2Ki7iihHbuKKx5f/eDm54Ip7P0NnpT fAxcvuoh3b8zZAZysTi1JJSge1H12gk= X-MC-Unique: 8ra6ExuaM-iJe1gq5qtjjw-1 X-Mimecast-MFC-AGG-ID: 8ra6ExuaM-iJe1gq5qtjjw_1753104079 To: devel@lists.libvirt.org Subject: [PATCH 13/19] virSecuritySELinuxGenNewContext: Refactor cleanup Date: Mon, 21 Jul 2025 15:20:54 +0200 Message-ID: <4aa239841ed1f61f21d8beedcdb7c8e709b23bbc.1753103831.git.pkrempa@redhat.com> 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: qnyRX9CSZa2M85J604XOiXFbY8azX3pmrJ2itBkCpj8_1753104079 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 5TURO4373AYW77JGC5N74NNH26NG3PRJ X-Message-ID-Hash: 5TURO4373AYW77JGC5N74NNH26NG3PRJ 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: 1753104405696116600 Content-Type: text/plain; charset="utf-8" From: Peter Krempa Use automatic freeing of temporary variables and remove cleanup section. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/security/security_selinux.c | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index 55a5593fa5..67d9da461a 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -650,11 +650,10 @@ virSecuritySELinuxGenNewContext(const char *baseconte= xt, const char *mcs, bool isObjectContext) { - context_t context =3D NULL; - char *ret =3D NULL; + g_autoptr(context_s_t) context =3D NULL; const char *str; - char *ourSecContext =3D NULL; - context_t ourContext =3D NULL; + g_autofree char *ourSecContext =3D NULL; + g_autoptr(context_s_t) ourContext =3D NULL; VIR_DEBUG("basecontext=3D%s mcs=3D%s isObjectContext=3D%d", basecontext, mcs, isObjectContext); @@ -662,13 +661,13 @@ virSecuritySELinuxGenNewContext(const char *baseconte= xt, if (getcon_raw(&ourSecContext) < 0) { virReportSystemError(errno, "%s", _("Unable to get current process SELinux cont= ext")); - goto cleanup; + return NULL; } if (!(ourContext =3D context_new(ourSecContext))) { virReportSystemError(errno, _("Unable to parse current SELinux context '%= 1$s'"), ourSecContext); - goto cleanup; + return NULL; } VIR_DEBUG("process=3D%s", ourSecContext); @@ -676,7 +675,7 @@ virSecuritySELinuxGenNewContext(const char *basecontext, virReportSystemError(errno, _("Unable to parse base SELinux context '%1$s= '"), basecontext); - goto cleanup; + return NULL; } if (context_user_set(context, @@ -684,7 +683,7 @@ virSecuritySELinuxGenNewContext(const char *basecontext, virReportSystemError(errno, _("Unable to set SELinux context user '%1$s'"= ), context_user_get(ourContext)); - goto cleanup; + return NULL; } if (!isObjectContext && @@ -693,27 +692,23 @@ virSecuritySELinuxGenNewContext(const char *baseconte= xt, virReportSystemError(errno, _("Unable to set SELinux context role '%1$s'"= ), context_role_get(ourContext)); - goto cleanup; + return NULL; } if (context_range_set(context, mcs) !=3D 0) { virReportSystemError(errno, _("Unable to set SELinux context MCS '%1$s'"), mcs); - goto cleanup; + return NULL; } if (!(str =3D context_str(context))) { virReportSystemError(errno, "%s", _("Unable to format SELinux context")); - goto cleanup; + return NULL; } - ret =3D g_strdup(str); - VIR_DEBUG("Generated context '%s'", ret); - cleanup: - freecon(ourSecContext); - context_free(ourContext); - context_free(context); - return ret; + + VIR_DEBUG("Generated context '%s'", str); + return g_strdup(str); } --=20 2.50.0 From nobody Mon Sep 8 17:12:43 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=1753104421; cv=none; d=zohomail.com; s=zohoarc; b=TJeNLKLl5x4PgxNAAIZVvJFrGIkgBJbEdQ9P7T9jSZX3EgBpJybuiAiRt6sH0Efk/HBPmazfwzbfznVHOz6D1pMRjifaqyQqOR5NEewQrIUNdLtZxxbzUlc3CB1dvxDr3Ezp18QwMGYb7cbQmpHva1ong7qxYusIODcn2aNc/fY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1753104421; 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=J3CNAd+bYsExzBpIXrS8O0I7t9AphI6QwuMWV5oNa18=; b=j9h9xlR0k1dsoLin0ItrT/PAwgxpGR7PEE3ccR1hV2tD31yww+oK+PYWrQzMAn/m4gsqqDc3WPcxHtReEWOkmAhAMUamdS2BmI65LjXXNbpoDXpx8JVIx83uzGI/6yjWdHaWEZgK+PoX7hFclgG0acXQyW050M6cl40r1314Jec= 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 1753104421055726.6542581486976; Mon, 21 Jul 2025 06:27:01 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id ECCB21413; Mon, 21 Jul 2025 09:26:59 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 383571423; Mon, 21 Jul 2025 09:21:52 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id ED47D140D; Mon, 21 Jul 2025 09:21:44 -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 A325A10F2 for ; Mon, 21 Jul 2025 09:21:22 -0400 (EDT) Received: from mx-prod-mc-02.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-121-24j25ZCLMbuLP80wWzbxMg-1; Mon, 21 Jul 2025 09:21:21 -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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3B98D1956066 for ; Mon, 21 Jul 2025 13:21:20 +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 7AB1A18002B6 for ; Mon, 21 Jul 2025 13:21:19 +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=1753104082; 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=73csJfQf/ve1dj79EJ/ZkmTSw4kxaPpAMrvcgFvxjOc=; b=GbGQWbRH0V2enq0y3Wmbw1EUxRo8YwQnMAAQfQ/eqBTMgKU2eVNJDy7Dd/tzeU3R1wcQG9 hl278sr1djK7x8Bw+AjRbJ9VKME/Leu6CLKEJb/CFI1TvJat5UCDYgT36+6EkS22Y1HfqF czkAhH1RGdj1zd9nScehpgY7yTEs4cI= X-MC-Unique: 24j25ZCLMbuLP80wWzbxMg-1 X-Mimecast-MFC-AGG-ID: 24j25ZCLMbuLP80wWzbxMg_1753104080 To: devel@lists.libvirt.org Subject: [PATCH 14/19] virSecuritySELinuxReserveLabel: Refactor cleanup Date: Mon, 21 Jul 2025 15:20:55 +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: bn5ERr-Fne6EMiUsiSVpVxWw-RWNB1gKJ_U6WOxxweU_1753104080 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: DBAW4AI4VH2BSTZY7BQE4SUDM5GPLYP3 X-Message-ID-Hash: DBAW4AI4VH2BSTZY7BQE4SUDM5GPLYP3 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: 1753104421750116600 Content-Type: text/plain; charset="utf-8" From: Peter Krempa Automatically free temporary variables in order to remove 'cleanup' section. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/security/security_selinux.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index 67d9da461a..3004320380 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -1025,8 +1025,8 @@ virSecuritySELinuxReserveLabel(virSecurityManager *mg= r, virDomainDef *def, pid_t pid) { - char *pctx; - context_t ctx =3D NULL; + g_autofree char *pctx =3D NULL; + g_autoptr(context_s_t) ctx =3D NULL; const char *mcs; int rv; virSecurityLabelDef *seclabel; @@ -1045,31 +1045,23 @@ virSecuritySELinuxReserveLabel(virSecurityManager *= mgr, ctx =3D context_new(pctx); if (!ctx) - goto error; + return -1; mcs =3D context_range_get(ctx); if (!mcs) - goto error; + return -1; if ((rv =3D virSecuritySELinuxMCSAdd(mgr, mcs)) < 0) - goto error; + return -1; if (rv =3D=3D 1) { virReportError(VIR_ERR_INTERNAL_ERROR, _("MCS level for existing domain label %1$s already= reserved"), (char*)pctx); - goto error; + return -1; } - freecon(pctx); - context_free(ctx); - return 0; - - error: - freecon(pctx); - context_free(ctx); - return -1; } --=20 2.50.0 From nobody Mon Sep 8 17:12:43 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=1753104462; cv=none; d=zohomail.com; s=zohoarc; b=ELzy5GwBVMzf5+OluJA/duCa6M4vBWwfb8tMECzLFjXJR9hhyHA9/4lF6b/bohArEWe/i/A7mt0MgV03dqpqzTBG+wdktq5hrgrq1CP2Rt1WuJZxHXBYdLovYgMJixFZimpvCqagTO0nBfpE8ONCns8mxMEcrsgJtzAI4ka1kxs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1753104462; 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=T6WKtPxFZ+GIfjFTOSqi8YIRhzYihRLK++UiGHTPDig=; b=TmgiFl1sbV3E1rDUOwKNYjskxzVSCbsnBvbRstGAZImNKRQEKHNh2GFr8HBJeaEXCwJWFI3vGZyo10trqj1O5mL3pYYfpj0PwleJ1tF5Y+P5ovvo8RjoXXG1gCgVMb7+fiELaF42SZPmF6UZXlql0ALq3xZZTlrZ5/vN6BMDgJ4= 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 1753104461826499.1123965904045; Mon, 21 Jul 2025 06:27:41 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id D097A129A; Mon, 21 Jul 2025 09:27:40 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 3F1E21392; Mon, 21 Jul 2025 09:21:57 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 13E5E1265; Mon, 21 Jul 2025 09:21:46 -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 E4D581247 for ; Mon, 21 Jul 2025 09:21:23 -0400 (EDT) Received: from mx-prod-mc-04.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-98-GFQm_2k3M5qBGXIoa_kvWA-1; Mon, 21 Jul 2025 09:21:22 -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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8022119560B5 for ; Mon, 21 Jul 2025 13:21:21 +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 B0814180035E for ; Mon, 21 Jul 2025 13:21:20 +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=1753104083; 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=lRa4Pm+W7z46c/avdFO97ocwaI/PqEzDxJrOxaCatUc=; b=irjpQiWspIEXJWR9rwVxP8W1J8DynsDFBNVpOv+h/0AXaTelZeHNCFGWRXAvn1TJmcxNG/ 5lq3gvZd0/TJU7pVswKDvhUlOnWlDxAg3bDZLy799F+xjeuWlJ/7O1+30X31e0SOObKTx/ 9N5twv0dOApMZV6AHRGUVNUMoMYO1BY= X-MC-Unique: GFQm_2k3M5qBGXIoa_kvWA-1 X-Mimecast-MFC-AGG-ID: GFQm_2k3M5qBGXIoa_kvWA_1753104081 To: devel@lists.libvirt.org Subject: [PATCH 15/19] virSecuritySELinuxGetProcessLabel: Automatically free 'ctx' temp variable Date: Mon, 21 Jul 2025 15:20:56 +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: CSBtE0pnaofXt03Sw9HKb1T7JcsmBrmYRJQ9PRas7WE_1753104081 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: GWXKPILJTBHMAOGTZWCKEMSLBJAMJNUJ X-Message-ID-Hash: GWXKPILJTBHMAOGTZWCKEMSLBJAMJNUJ 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: 1753104464291116600 Content-Type: text/plain; charset="utf-8" From: Peter Krempa Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/security/security_selinux.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index 3004320380..54f12d044f 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -1271,7 +1271,7 @@ virSecuritySELinuxGetProcessLabel(virSecurityManager = *mgr G_GNUC_UNUSED, pid_t pid, virSecurityLabelPtr sec) { - char *ctx; + g_autofree char *ctx =3D NULL; if (getpidcon_raw(pid, &ctx) =3D=3D -1) { virReportSystemError(errno, @@ -1284,12 +1284,9 @@ virSecuritySELinuxGetProcessLabel(virSecurityManager= *mgr G_GNUC_UNUSED, virReportError(VIR_ERR_INTERNAL_ERROR, _("security label exceeds maximum length: %1$d"), VIR_SECURITY_LABEL_BUFLEN - 1); - freecon(ctx); return -1; } - freecon(ctx); - VIR_DEBUG("label=3D%s", sec->label); sec->enforcing =3D security_getenforce(); if (sec->enforcing =3D=3D -1) { --=20 2.50.0 From nobody Mon Sep 8 17:12:43 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=1753104438; cv=none; d=zohomail.com; s=zohoarc; b=GDEYaXMj+sfk3homuCq8l143M8mmK2pmwnOhF8qMtBkNHyL71MS+Rg7M3a6lTi8XSJmwflBDM/D985CGNxxnI78AEgu8xQWzvsW9Gd8Nd3JXiuhmZGK2qCkuhqeyy+1sRhvXklYeQiR2sjBkmQsz+CL90czqTCj6Pwe+uoVVZ9A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1753104438; 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=84Bc0tjS8yVWPZvC3rzS5Nu8I0gEdp1yHgW/t8iPaNk=; b=nXWle72G07eelswBxUyue0It6Zz1ztgqo1y1MB9YyglpQ9Rfo5/4OzV5Gap9XhL46C0MLV+XXNJiviaqHVEuduU1q1M+6X6v1pzYPFE1IKQ/rjzsyFC7Zs0LDGZIHns8Yi95ZqLdLkfVIwV6UFa02+3qqjW5GMIc3zc8tV0Rz2A= 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 1753104438338168.06623982587223; Mon, 21 Jul 2025 06:27:18 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 61F671423; Mon, 21 Jul 2025 09:27:17 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 111FFE67; Mon, 21 Jul 2025 09:21:55 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 02FFA12E0; Mon, 21 Jul 2025 09:21:45 -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 779F7E5B for ; Mon, 21 Jul 2025 09:21:25 -0400 (EDT) Received: from mx-prod-mc-02.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-639-akqb20WRMoCnV0AJ5Ip5aA-1; Mon, 21 Jul 2025 09:21:23 -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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BA31B1956089 for ; Mon, 21 Jul 2025 13:21:22 +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 0658D18002B6 for ; Mon, 21 Jul 2025 13:21:21 +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=1753104085; 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=UhMaIRDYPqOrUtVrc5wRFtUg/mCooCyPhPPlcTW1bM4=; b=VxyoQinoLPTWF6c9j0z6s47HunWkKqnS5GeMLyFrSKEojZD7B0HQ9Y0AnWIrP/sBGaShOt dummIKSQ1N63iInXdXyCttoVSbwLV2hp1Lh2HR+HehOVgGhfqMLi8OXv9FKYNIXcTTbKxN +HBah9BFqmPxAIfTnhJ0zGVzvxmMgdI= X-MC-Unique: akqb20WRMoCnV0AJ5Ip5aA-1 X-Mimecast-MFC-AGG-ID: akqb20WRMoCnV0AJ5Ip5aA_1753104082 To: devel@lists.libvirt.org Subject: [PATCH 16/19] virSecuritySELinuxSetFilecon: Automatically free 'econ' temp variable Date: Mon, 21 Jul 2025 15:20:57 +0200 Message-ID: <8043b7404fd5edd53281fa18295fdad1b0025296.1753103831.git.pkrempa@redhat.com> 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: 0TThmjD9lWEFblydf1QfUcmfi3lUbl10AefRm7ItPvY_1753104082 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: LAUKJB4XGGESB2TWXHMXY7ATK7NLWXCE X-Message-ID-Hash: LAUKJB4XGGESB2TWXHMXY7ATK7NLWXCE 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: 1753104439925116600 Content-Type: text/plain; charset="utf-8" From: Peter Krempa Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/security/security_selinux.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index 54f12d044f..b390e0c95f 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -1380,7 +1380,7 @@ virSecuritySELinuxSetFilecon(virSecurityManager *mgr, bool remember) { bool privileged =3D virSecurityManagerGetPrivileged(mgr); - char *econ =3D NULL; + g_autofree char *econ =3D NULL; int refcount; int rc; bool rollback =3D false; @@ -1454,7 +1454,6 @@ virSecuritySELinuxSetFilecon(virSecurityManager *mgr, virErrorRestore(&origerr); } - freecon(econ); return ret; } --=20 2.50.0 From nobody Mon Sep 8 17:12:43 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=1753104478; cv=none; d=zohomail.com; s=zohoarc; b=FTIfeFi2+6xFjiFqTBT9E4cX/D+ySuajMnslqRX54zcifKmEFXxUILO8FoKtVpqvjRV3WWarzbeM/AeGjQLppBKGriZ0sUfanRIx50ioYZ7qigxe/3ejlFoQnInzUY/JV02xOduv/FKp+aeLVan8mw1hu99L67oAr0688eXlVpA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1753104478; 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=weq+Lm0EXtO3GaCNHdH19AGfxCVoEOGK9SszfnsQNPc=; b=kEA5KbkwgYGD/3dZPKX6qPKUp1h29JGrVZWKfB/Yi14mJPOEelEgt2or4/0r1yVwUZ7aCegIq10zGNZGjJotWHjtPhrpcwxIzPxMx3QLHcMGjBZ31peUTv27X5f+nu70jNCUXJOvl1juQAW6FLYqzPHYpQ/S4MrCkcJunCI0HTI= 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 1753104478204667.6074745990418; Mon, 21 Jul 2025 06:27:58 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 3A3B6E1F; Mon, 21 Jul 2025 09:27:57 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id EB9F01525; Mon, 21 Jul 2025 09:21:59 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id B5AAF12CB; Mon, 21 Jul 2025 09:21:46 -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 8503E11D8 for ; Mon, 21 Jul 2025 09:21:26 -0400 (EDT) Received: from mx-prod-mc-06.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-332-7_8cqFS0PqqGadylYzWBqg-1; Mon, 21 Jul 2025 09:21:24 -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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EC00D1800281 for ; Mon, 21 Jul 2025 13:21:23 +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 3C712180035E for ; Mon, 21 Jul 2025 13:21:23 +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=1753104086; 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=McpJiKasMwM1reUT13zJsfGJymlVfh+qUOhAnGiOYwU=; b=V/7QmS7XmHJiqoE20cnucq5Wk4TkqsYuAJP+ld9zAYtTxHepRCmMpKnumzTwl5vkJwrvXC DJSu/hi+e5f8EcLDcdk5XEHKnhflSO2J1K/I/lOys9maEDsmpZ6YWIP1PkQRFuXR/t0isp rH3l3E9Wwmiehh33j99M04amH83p+4s= X-MC-Unique: 7_8cqFS0PqqGadylYzWBqg-1 X-Mimecast-MFC-AGG-ID: 7_8cqFS0PqqGadylYzWBqg_1753104084 To: devel@lists.libvirt.org Subject: [PATCH 17/19] virSecuritySELinuxRestoreInputLabel: Return values directly Date: Mon, 21 Jul 2025 15:20:58 +0200 Message-ID: <8350c8637aeaa545cd6786d615ccdbc8185f365b.1753103831.git.pkrempa@redhat.com> 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: Vp8K1rKwfqMS-C3AyXxpFbakyJzrknc6TyiwupnVxDg_1753104084 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: LIEPMEG6RTP732LDRGABJIPI7IQZJSHD X-Message-ID-Hash: LIEPMEG6RTP732LDRGABJIPI7IQZJSHD 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: 1753104480588116600 Content-Type: text/plain; charset="utf-8" From: Peter Krempa Skip the use of temporary variable. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/security/security_selinux.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index b390e0c95f..b16ab14dfe 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -1602,7 +1602,6 @@ virSecuritySELinuxRestoreInputLabel(virSecurityManage= r *mgr, virDomainDef *def, virDomainInputDef *input) { - int rc =3D 0; virSecurityLabelDef *seclabel; seclabel =3D virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX_NAM= E); @@ -1612,8 +1611,7 @@ virSecuritySELinuxRestoreInputLabel(virSecurityManage= r *mgr, switch ((virDomainInputType)input->type) { case VIR_DOMAIN_INPUT_TYPE_PASSTHROUGH: case VIR_DOMAIN_INPUT_TYPE_EVDEV: - rc =3D virSecuritySELinuxRestoreFileLabel(mgr, input->source.evdev= , true); - break; + return virSecuritySELinuxRestoreFileLabel(mgr, input->source.evdev= , true); case VIR_DOMAIN_INPUT_TYPE_MOUSE: case VIR_DOMAIN_INPUT_TYPE_TABLET: @@ -1622,7 +1620,7 @@ virSecuritySELinuxRestoreInputLabel(virSecurityManage= r *mgr, break; } - return rc; + return 0; } --=20 2.50.0 From nobody Mon Sep 8 17:12:43 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=1753104497; cv=none; d=zohomail.com; s=zohoarc; b=CqKJj2S3vUziwKN3ilzWXh3XdtJuBKFtiXDNWharBFwh0VlQUIC2z1JKo6hZW6W1g2LcW5h+vUf07++iMOfC6676QJbKfED8Wcv/zFqo7/J33TksKSxbGlikKIo8EDy5h9n7nwu8okVOfSt5OcIxJwhzMDk/eH8vlSgoVjCCK+M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1753104497; 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=xM8xb75KJ9hEOtcCykhyzy6fNt9YZ4QqDWXbLyCL5gs=; b=Ri5xjVOkFUAMWTEGvH3pW/pfcTkBPauBpCGzIC9kIwQYP8eFQeDsfsq+OErNWMeble9kgrXWcL8BpwKuaeb1T8RSDCtPb7o9AEGvdmp1s+qNH08zNu5UrEWYrfae4q4bwD1LsXwapn6rtfX3xPJnvz5KurOymXGd7gLN0D70HYU= 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 1753104497164101.9916455532624; Mon, 21 Jul 2025 06:28:17 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 3ACE7B73; Mon, 21 Jul 2025 09:28:16 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id A415E14ED; Mon, 21 Jul 2025 09:22:02 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 2AC2CE8B; Mon, 21 Jul 2025 09:21:48 -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 5139911E1 for ; Mon, 21 Jul 2025 09:21:27 -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-447-80u4z4mqMH2DAsRGVgPIHA-1; Mon, 21 Jul 2025 09:21:25 -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 226CE1800C36 for ; Mon, 21 Jul 2025 13:21:25 +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 6128E18002B6 for ; Mon, 21 Jul 2025 13:21:24 +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=1753104087; 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=w69WYTiwvncWGk4wblvI4qCDN9Lq32yq3LkSk4i0GYo=; b=f36eyBAIO/umnOrvBbV4/YhCE6AwzSFztocdlzGXW3FFLTFJgSNG0TRISzG8ie8rknv0i9 3hnU+UzmpM99TumpxE3xrBCEZmd2bw4GveeDLQ1MpbAz6iquTOHHHvsUkxNwXxwmtmQdFH l0FCm6YPIqDzVWX+R3Om4gMCDo/2AE4= X-MC-Unique: 80u4z4mqMH2DAsRGVgPIHA-1 X-Mimecast-MFC-AGG-ID: 80u4z4mqMH2DAsRGVgPIHA_1753104085 To: devel@lists.libvirt.org Subject: [PATCH 18/19] virSecuritySELinuxGenImageLabel: Refactor cleanup Date: Mon, 21 Jul 2025 15:20:59 +0200 Message-ID: <378ddbaef98bbe0131053387d4e612b98dbc19c1.1753103831.git.pkrempa@redhat.com> 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: 6Np4sIbW6rYCkMHQC7t_c5EPlClKe-p6tZEuNqh_mSU_1753104085 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: PMRHFQIHWUQECXPETKZNYJULJWJWEVDH X-Message-ID-Hash: PMRHFQIHWUQECXPETKZNYJULJWJWEVDH 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: 1753104498762116600 Content-Type: text/plain; charset="utf-8" From: Peter Krempa Automatically free temporary variables in order to remove 'cleanup' section. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/security/security_selinux.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index b16ab14dfe..9d14e33340 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -3495,34 +3495,29 @@ virSecuritySELinuxGenImageLabel(virSecurityManager = *mgr, virSecurityLabelDef *secdef; virSecuritySELinuxData *data =3D virSecurityManagerGetPrivateData(mgr); const char *range; - context_t ctx =3D NULL; - char *label =3D NULL; - char *mcs =3D NULL; + g_autoptr(context_s_t) ctx =3D NULL; secdef =3D virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX_NAME); if (secdef =3D=3D NULL) - goto cleanup; + return NULL; if (secdef->label) { ctx =3D context_new(secdef->label); if (!ctx) { virReportSystemError(errno, _("unable to create selinux contex= t for: %1$s"), secdef->label); - goto cleanup; + return NULL; } range =3D context_range_get(ctx); if (range) { - mcs =3D g_strdup(range); - if (!(label =3D virSecuritySELinuxGenNewContext(data->file_con= text, - mcs, true))) - goto cleanup; + g_autofree char *mcs =3D g_strdup(range); + + return virSecuritySELinuxGenNewContext(data->file_context, + mcs, true); } } - cleanup: - context_free(ctx); - VIR_FREE(mcs); - return label; + return NULL; } static char * --=20 2.50.0 From nobody Mon Sep 8 17:12:43 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=1753104514; cv=none; d=zohomail.com; s=zohoarc; b=VkEZ6Kl8YPytwiOTsWr5Q6UIZFeGEk8+vE/3CpyyQatRv6Szh1SenSamO8nyGFjlGXex3FM5hXUfXkC/NUQy7JUAMTXbtFYHNMqoFpVem7XA9baHN7RkiCDcPy/hwbDg5GR960zOPBCHfURIGCrbf7D47Beu3hQC2we01bbW+HE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1753104514; 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=IjZAjdA3UmHbhy+ceH1lcPusa5sK3ChjBF8PYxyzOsw=; b=W1hzEp7QaaDO6/e4n9TIAP0YPi1gFq6ouSECL7le2JDYVOPA2NMgXrUYe7pQ+JdvlGdGW+CCbu05JhPV1oJHBxWPhuwTm1pAsS9MsxlZIYwaNkDFqMNi53VHs+UXnWZEph/1S2xLjv9o02CFycUyloyuFYPVbgYxfvwdbOkI1jk= 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 1753104514906896.6702676181454; Mon, 21 Jul 2025 06:28:34 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id E64679D2; Mon, 21 Jul 2025 09:28:33 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 800C71529; Mon, 21 Jul 2025 09:22:05 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 9880F11CD; Mon, 21 Jul 2025 09:21:50 -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 30F7E146A for ; Mon, 21 Jul 2025 09:21:32 -0400 (EDT) Received: from mx-prod-mc-01.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-564-BG_PGMcKOLe3lcaSSlJhFQ-1; Mon, 21 Jul 2025 09:21:27 -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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4F2F01944D04 for ; Mon, 21 Jul 2025 13:21:26 +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 932FE1800D82 for ; Mon, 21 Jul 2025 13:21:25 +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=1753104091; 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=lX9w+YoAW1e8iJrXXa3PghudoEHSeGHmdpJCDjMWq+E=; b=Tnc3jzZG6IOxFjN9EJ0hSpeXAVpY5rDHYO0H5IrBmjNgCV+nLKB7ftGS1LrlfrIgSwRnSW U0WXkrsd/1xln+Qr7tH3SRRxzBo/lekIGhrzjwbGMEkQCLoF1n625X2qCOAlHktyTkKXYc rf616IJzu/tH057HZpKKevHXTb2w3zk= X-MC-Unique: BG_PGMcKOLe3lcaSSlJhFQ-1 X-Mimecast-MFC-AGG-ID: BG_PGMcKOLe3lcaSSlJhFQ_1753104086 To: devel@lists.libvirt.org Subject: [PATCH 19/19] virSecuritySELinuxGetSecurityMountOptions: refactor printing Date: Mon, 21 Jul 2025 15:21:00 +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: nt-hY9Eh2ioa3uZje--OnMef90YxCdfBqruolzmcwFw_1753104086 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: BIT2TWQ5SHP5YFVSC3AI2WIHCPP6UXMD X-Message-ID-Hash: BIT2TWQ5SHP5YFVSC3AI2WIHCPP6UXMD 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: 1753104516930116600 Content-Type: text/plain; charset="utf-8" From: Peter Krempa Fix linebreaks and remove the use of ternary operator. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/security/security_selinux.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index 9d14e33340..fa5d1568eb 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -3526,23 +3526,24 @@ virSecuritySELinuxGetSecurityMountOptions(virSecuri= tyManager *mgr, { char *opts =3D NULL; virSecurityLabelDef *secdef; + const char *imagelabel =3D NULL; if ((secdef =3D virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX_= NAME))) { if (!secdef->imagelabel) secdef->imagelabel =3D virSecuritySELinuxGenImageLabel(mgr, de= f); if (secdef->imagelabel) { - opts =3D g_strdup_printf( - ",context=3D\"%s\"", + opts =3D g_strdup_printf(",context=3D\"%s\"", (const char*) secdef->imagelabel); } + + imagelabel =3D secdef->imagelabel; } if (!opts) opts =3D g_strdup(""); - VIR_DEBUG("imageLabel=3D%s opts=3D%s", - secdef ? secdef->imagelabel : "(null)", opts); + VIR_DEBUG("imageLabel=3D%s opts=3D%s", NULLSTR(imagelabel), opts); return opts; } --=20 2.50.0