From nobody Wed Jan 15 09:15:03 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1682911263; cv=none; d=zohomail.com; s=zohoarc; b=MIsIJYxD/P3sazcBdXfjYeaiwL2EDGbn7BQv1l93v7Ok9VYnUg1EJuDl/qQjYqt27VkcnKmZWYcJcdPzb17PVRflA6AIDfyrWCk5VqL/w4b0BEDISq1bdWpgLkU2gnYwvrQnGvnvVEoGyTHBDz5o2/0LHnViCWbmbWLs4K67bwE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682911263; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=GhRziREX5AieQZ0UJfu7NQ/YLZXXsyb45PEPoo/84hs=; b=L2NzN4FbzxsnBmhCl+zRXPolKPSK4ONnjwBa5VxKRlyAa33Kx6Bp0TSbRKxwfwGQ0URmojPsi6qAVtQyJuSU/X+nKizbp6Sd2qPQ9JKv24n1BZ9tRZ6SiJpoub3EOjVYRcl7hiTcK6nvQynLpsb9Sqp69ina48kyirBMoMpDUq8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1682911263966433.6587428443654; Sun, 30 Apr 2023 20:21:03 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-361-oBDoN7YKPRypwX5wQpSG2w-1; Sun, 30 Apr 2023 23:20:18 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C8FB7811E7E; Mon, 1 May 2023 03:20:15 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id B1BC351E3; Mon, 1 May 2023 03:20:15 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id DE127193F51C; Mon, 1 May 2023 03:20:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id D22B11946A49 for ; Mon, 1 May 2023 03:20:05 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 0FEF7463ECB; Mon, 1 May 2023 03:19:47 +0000 (UTC) Received: from vhost3.router.laine.org (unknown [10.22.8.105]) by smtp.corp.redhat.com (Postfix) with ESMTP id EBFFE475022 for ; Mon, 1 May 2023 03:19:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682911262; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=GhRziREX5AieQZ0UJfu7NQ/YLZXXsyb45PEPoo/84hs=; b=cahxmbGppkJntpsasG6pGZ5Xe9r2DWozKdZRAjIcUVVPUdszOUYBxZSTiRNSCjAk9dkO6F f77BblKfyVcAImxYSaN8UB+MerZ6Zvjwdeo/bE0OqpiWmAFNM0H8EQmCsKyLQjy6zqMeP6 4+xtAH3gPr9UCwooWLkdEZEo+7O9jw8= X-MC-Unique: oBDoN7YKPRypwX5wQpSG2w-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Laine Stump To: libvir-list@redhat.com Subject: [libvirt PATCH 19/28] util: check for 0 args when applying iptables rule Date: Sun, 30 Apr 2023 23:19:34 -0400 Message-Id: <20230501031943.288145-20-laine@redhat.com> In-Reply-To: <20230501031943.288145-1-laine@redhat.com> References: <20230501031943.288145-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1682911265495100001 Content-Type: text/plain; charset="utf-8"; x-default="true" In normal practice a firewall rule should never have 0 args by the time it gets to the Apply stage, but at some time while debugging auto-rollback exactly that happened (due to a bug that was since squashed), and having a check for it helped debugging, so let's permanently check for it (the nftables version of ApplyRule already has this check). Signed-off-by: Laine Stump Reviewed-by: Daniel P. Berrang=C3=A9 --- src/util/viriptables.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/util/viriptables.c b/src/util/viriptables.c index 96b69daf68..4e3188e4d1 100644 --- a/src/util/viriptables.c +++ b/src/util/viriptables.c @@ -71,10 +71,11 @@ virIptablesApplyFirewallRule(virFirewall *firewall G_GN= UC_UNUSED, { virFirewallLayer layer =3D virFirewallRuleGetLayer(rule); const char *bin =3D virIptablesLayerCommandTypeToString(layer); + size_t count =3D virFirewallRuleGetArgCount(rule); g_autoptr(virCommand) cmd =3D NULL; g_autofree char *cmdStr =3D NULL; g_autofree char *error =3D NULL; - size_t i, count; + size_t i; int status; =20 if (!bin) { @@ -83,6 +84,12 @@ virIptablesApplyFirewallRule(virFirewall *firewall G_GNU= C_UNUSED, return -1; } =20 + if (count =3D=3D 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Can't apply empty firewall rule")); + return -1; + } + cmd =3D virCommandNewArgList(bin, NULL); =20 /* lock to assure nobody else is messing with the tables while we are = */ @@ -98,7 +105,6 @@ virIptablesApplyFirewallRule(virFirewall *firewall G_GNU= C_UNUSED, break; } =20 - count =3D virFirewallRuleGetArgCount(rule); for (i =3D 0; i < count; i++) virCommandAddArg(cmd, virFirewallRuleGetArg(rule, i)); =20 --=20 2.39.2