From nobody Tue Sep 9 19:25:38 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 --- 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