From nobody Fri Dec 12 14:05:30 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=1764252684; cv=none; d=zohomail.com; s=zohoarc; b=VK61ImY6GDpQG4rBfjWNQ2zJ3gNippXg3EMeygFOTnFH3c7QFwORVRf4K9xGmD7TXY4Fjxf3ZVo/PR0ltttkmDJCbU6cvQE2APhYN1Sa6FG8f36VsTs2xdErzvWhpfKJFp6K5uUxbeCK6gx5vaDUvJt7nWrHRluxLutC4SueW7U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1764252684; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner: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=Hoiv3TRkLY50Ii3HyJOJ/nnOEHGLSh1IN1gM4cFbkXM=; b=kLxmf9RAvPmvh/DXWHKthQCrRKhB2tHOkzdl7nvgUg3R1XhvgN8lrL+hib3S5yIBkQ/AirUcpbZGnhLYsE0Mv3azh/Aly/Wi9RUvDGAwirPfPQbfNy5+xPnpngWWHFUFRvKqKNcQNlTa5J4OsiSaoDaYsW3WLS+mQSNqkZX38Hk= 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 1764252684422165.89008177522453; Thu, 27 Nov 2025 06:11:24 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id 3F85744B79; Thu, 27 Nov 2025 09:00:40 -0500 (EST) Received: from [172.19.199.74] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 3AED644C56; Thu, 27 Nov 2025 08:54:34 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id 8DFC0418CA; Thu, 27 Nov 2025 08:52:38 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 0297044BCE for ; Thu, 27 Nov 2025 08:51:17 -0500 (EST) 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-446-vMaym0vdNqWbZgrHOXhogA-1; Thu, 27 Nov 2025 08:51:15 -0500 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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 B6F5A195608A for ; Thu, 27 Nov 2025 13:51:14 +0000 (UTC) Received: from moe (unknown [10.43.3.236]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0C58B1800346 for ; Thu, 27 Nov 2025 13:51:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1764251477; 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=Hoiv3TRkLY50Ii3HyJOJ/nnOEHGLSh1IN1gM4cFbkXM=; b=OQSGtBmVdRoqbr3r6cLTrYwWNl3GX/Uk3/RAzcGFHzGXAiiKjj+S1YDFWB0QNYLU1e5Hlv n3vnPhjAgMTkWMiIV94OZBcpVcup5H6ol89X3uKbCHQIkWCkx3fYLA3pNPBmb8lpmR4VMf FzqcDpsbM1ekbtwsLzOlV6dNYHOZsV0= X-MC-Unique: vMaym0vdNqWbZgrHOXhogA-1 X-Mimecast-MFC-AGG-ID: vMaym0vdNqWbZgrHOXhogA_1764251474 To: devel@lists.libvirt.org Subject: [PATCH 7/8] iptablesPrivateChainCreate: Avoid modifying const string Date: Thu, 27 Nov 2025 14:51:02 +0100 Message-ID: <2ec89ac0de961234e0a7f5d56cc4fc6f97c69ef9.1764251323.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: r5dXKfdynhLwRTZ3b0KTXqdoerjPobrtDNtjqyOM1xc_1764251474 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: B4GS44E7RCNP2T372PTPYGO5LFK5LSTB X-Message-ID-Hash: B4GS44E7RCNP2T372PTPYGO5LFK5LSTB X-MailFrom: mprivozn@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1764252685709019200 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik The iptablesPrivateChainCreate() function is given an array of const strings. This constitutes a promise to the caller that the data is not modified. But inside the data is modified anyway (to cut out some parts of the data). Well, with a help from g_strdup() the promise can be kept. Signed-off-by: Michal Privoznik --- src/network/network_iptables.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/network/network_iptables.c b/src/network/network_iptables.c index 19dcfc7c8b..d21ce59b70 100644 --- a/src/network/network_iptables.c +++ b/src/network/network_iptables.c @@ -84,7 +84,7 @@ iptablesPrivateChainCreate(virFirewall *fw, { iptablesGlobalChainData *data =3D opaque; g_autoptr(GHashTable) chains =3D virHashNew(NULL); - g_autoptr(GHashTable) links =3D virHashNew(NULL); + g_autoptr(GHashTable) links =3D virHashNew(g_free); const char *const *line; size_t i; =20 @@ -96,16 +96,18 @@ iptablesPrivateChainCreate(virFirewall *fw, if (virHashUpdateEntry(chains, tmp, (void *)0x1) < 0) return -1; } else if ((tmp =3D STRSKIP(*line, "-A "))) { /* eg "-A INPUT -j L= IBVIRT_INP" */ - char *sep =3D strchr(tmp, ' '); + const char *sep =3D strchr(tmp, ' '); =20 if (sep) { - char *target; + const char *target; =20 - *sep =3D '\0'; if ((target =3D STRSKIP(sep + 1, "-j "))) { - if (virHashUpdateEntry(links, target, - (char *)tmp) < 0) + char *chain =3D g_strndup(tmp, sep - tmp); + + if (virHashUpdateEntry(links, target, chain) < 0) { + g_free(chain); return -1; + } } } } --=20 2.51.2