From nobody Sun Feb 8 03:57:58 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1518713779148198.22990530545667; Thu, 15 Feb 2018 08:56:19 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C978C356D6; Thu, 15 Feb 2018 16:56:16 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 948122CFDF; Thu, 15 Feb 2018 16:56:16 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 4E809180CB21; Thu, 15 Feb 2018 16:56:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w1FGiD7g025952 for ; Thu, 15 Feb 2018 11:44:13 -0500 Received: by smtp.corp.redhat.com (Postfix) id 54E482024CAB; Thu, 15 Feb 2018 16:44:13 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id EB4C42024CA8; Thu, 15 Feb 2018 16:44:12 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 15 Feb 2018 16:43:42 +0000 Message-Id: <20180215164347.11538-38-berrange@redhat.com> In-Reply-To: <20180215164347.11538-1-berrange@redhat.com> References: <20180215164347.11538-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 37/42] nwfilter: add default: case to all switch statements X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 15 Feb 2018 16:56:18 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Even if the compiler has validated that all enum constants have case statements in a switch, it is not safe to omit a default: case statement. When assigning a value to a variable / struct field that is defined with an enum type, nothing prevents an invalid value being assigned. So defensive code must assume existance of invalid values and thus all switches should have a default: case. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/nwfilter/nwfilter_ebiptables_driver.c | 2 ++ src/nwfilter/nwfilter_gentech_driver.c | 23 ++++++++++++++++++++++- src/nwfilter/nwfilter_learnipaddr.c | 13 ++++++++++--- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/nwfilter/nwfilter_ebiptables_driver.c b/src/nwfilter/nwfil= ter_ebiptables_driver.c index c624337f4d..3d49884e2e 100644 --- a/src/nwfilter/nwfilter_ebiptables_driver.c +++ b/src/nwfilter/nwfilter_ebiptables_driver.c @@ -1129,6 +1129,8 @@ iptablesEnforceDirection(virFirewallPtr fw, break; case CTDIR_STATUS_OLD: break; + default: + break; } =20 if (rule->tt !=3D VIR_NWFILTER_RULE_DIRECTION_INOUT) diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter= _gentech_driver.c index 840d419bb4..25822d5185 100644 --- a/src/nwfilter/nwfilter_gentech_driver.c +++ b/src/nwfilter/nwfilter_gentech_driver.c @@ -405,6 +405,10 @@ virNWFilterIncludeDefToRuleInst(virNWFilterDriverState= Ptr driver, break; case INSTANTIATE_ALWAYS: break; + default: + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unexpected new filter action %d"), useNewFilter); + goto cleanup; } =20 if (VIR_APPEND_ELEMENT(inst->filters, @@ -555,6 +559,11 @@ virNWFilterDetermineMissingVarsRec(virNWFilterDefPtr f= ilter, break; case INSTANTIATE_ALWAYS: break; + default: + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unexpected new filter action %d"), useNe= wFilter); + rc =3D -1; + goto error; } =20 rc =3D virNWFilterDetermineMissingVarsRec(next_filter, @@ -562,7 +571,7 @@ virNWFilterDetermineMissingVarsRec(virNWFilterDefPtr fi= lter, missing_vars, useNewFilter, driver); - + error: virNWFilterHashTableFree(tmpvars); =20 virNWFilterObjUnlock(obj); @@ -701,6 +710,10 @@ virNWFilterDoInstantiate(const unsigned char *vmuuid, case INSTANTIATE_ALWAYS: instantiate =3D true; break; + default: + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unexpected new filter action %d"), useNewFilter); + goto err_exit; } =20 if (instantiate) { @@ -825,6 +838,10 @@ virNWFilterInstantiateFilterUpdate(virNWFilterDriverSt= atePtr driver, =20 case INSTANTIATE_ALWAYS: break; + default: + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unexpected new filter action %d"), useNewFilter); + goto err_exit_vars1; } =20 rc =3D virNWFilterDoInstantiate(vmuuid, techdriver, filter, @@ -1102,6 +1119,10 @@ virNWFilterDomainFWUpdateCB(virDomainObjPtr obj, _("Failure while applying current f= ilter on " "VM %s"), vm->name); break; + default: + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unexpected filter step %d"), cb->ste= p); + ret =3D -1; } if (ret) break; diff --git a/src/nwfilter/nwfilter_learnipaddr.c b/src/nwfilter/nwfilter_le= arnipaddr.c index 9ca0639576..e2a3704289 100644 --- a/src/nwfilter/nwfilter_learnipaddr.c +++ b/src/nwfilter/nwfilter_learnipaddr.c @@ -351,9 +351,14 @@ procDHCPOpts(struct dhcp *dhcp, int dhcp_opts_len, case DHCP_MSGT_DHCPOFFER: *vmaddr =3D dhcp->yiaddr; *howDetected =3D DETECT_DHCP; - break; + break; + default: + break; } } + break; + default: + break; } dhcp_opts_len -=3D (2 + dhcpopt->len); dhcpopt =3D (struct dhcp_option*)((char *)dhcpopt + 2 + dhcpopt->l= en); @@ -542,11 +547,13 @@ learnIPAddressThread(void *arg) case ARPOP_REPLY: vmaddr =3D arphdr->ar_sip; howDetected =3D DETECT_STATIC; - break; + break; case ARPOP_REQUEST: vmaddr =3D arphdr->ar_tip; howDetected =3D DETECT_STATIC; - break; + break; + default: + break; } } } else if (virMacAddrCmpRaw(&req->macaddr, --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list