From nobody Sun Feb 8 05:40:54 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 1518713564270700.799121493291; Thu, 15 Feb 2018 08:52:44 -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 B6A2978559; Thu, 15 Feb 2018 16:52:39 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 87AEE6A943; Thu, 15 Feb 2018 16:52:39 +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 48A224A481; Thu, 15 Feb 2018 16:52:39 +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 w1FGi75m025841 for ; Thu, 15 Feb 2018 11:44:07 -0500 Received: by smtp.corp.redhat.com (Postfix) id E95672024CAB; Thu, 15 Feb 2018 16:44:06 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8B9A62024CA8; Thu, 15 Feb 2018 16:44:06 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 15 Feb 2018 16:43:31 +0000 Message-Id: <20180215164347.11538-27-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 26/42] rpc: 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.28]); Thu, 15 Feb 2018 16:52:40 +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/rpc/virnetlibsshsession.c | 4 ++++ src/rpc/virnetservermdns.c | 5 ++++- src/rpc/virnetsshsession.c | 8 ++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/rpc/virnetlibsshsession.c b/src/rpc/virnetlibsshsession.c index 25f93cec97..25d65878b2 100644 --- a/src/rpc/virnetlibsshsession.c +++ b/src/rpc/virnetlibsshsession.c @@ -880,6 +880,10 @@ virNetLibsshAuthenticate(virNetLibsshSessionPtr sess) /* try to authenticate with password */ ret =3D virNetLibsshAuthenticatePassword(sess, auth); break; + default: + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unexpected SSH auth method %d"), auth->metho= d); + return -1; } =20 if (ret =3D=3D SSH_AUTH_ERROR) { diff --git a/src/rpc/virnetservermdns.c b/src/rpc/virnetservermdns.c index 0a2bc87322..7e3b7e632a 100644 --- a/src/rpc/virnetservermdns.c +++ b/src/rpc/virnetservermdns.c @@ -133,6 +133,7 @@ static void virNetServerMDNSGroupCallback(AvahiEntryGro= up *g ATTRIBUTE_UNUSED, =20 case AVAHI_ENTRY_GROUP_UNCOMMITED: case AVAHI_ENTRY_GROUP_REGISTERING: + default: ; } } @@ -249,7 +250,9 @@ static void virNetServerMDNSClientCallback(AvahiClient = *c, =20 case AVAHI_CLIENT_CONNECTING: VIR_DEBUG("Client connecting.... %p", mdns->client); - ; + break; + default: + break; } } =20 diff --git a/src/rpc/virnetsshsession.c b/src/rpc/virnetsshsession.c index e742175654..40256d0f9a 100644 --- a/src/rpc/virnetsshsession.c +++ b/src/rpc/virnetsshsession.c @@ -813,6 +813,10 @@ virNetSSHAuthenticateKeyboardInteractive(virNetSSHSess= ionPtr sess, case VIR_NET_SSH_AUTHCB_OK: /* everything went fine, let's continue */ break; + default: + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unexpected SSH auth code %d"), sess->authCbE= rr); + return -1; } =20 if (ret =3D=3D 0) @@ -897,6 +901,10 @@ virNetSSHAuthenticate(virNetSSHSessionPtr sess) if (strstr(auth_list, "password")) ret =3D virNetSSHAuthenticatePassword(sess, auth); break; + default: + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unexpected SSH auth method %d"), auth->metho= d); + return -1; } =20 /* return on success or error */ --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list