[libvirt] [PATCH] Coverity fix for virNetDevIPCheckIPv6ForwardingCallback

Cédric Bosdonnat cbosdonnat at suse.com
Fri Mar 24 12:04:07 UTC 2017


Add check for more than one RTA_OIF, even though this is rather
unlikely and get rid of the buggy switch / break.
---
 src/util/virnetdevip.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/util/virnetdevip.c b/src/util/virnetdevip.c
index c9ac6baf7..f5662413a 100644
--- a/src/util/virnetdevip.c
+++ b/src/util/virnetdevip.c
@@ -556,15 +556,17 @@ virNetDevIPCheckIPv6ForwardingCallback(const struct nlmsghdr *resp,
     if (resp->nlmsg_type != RTM_NEWROUTE)
         return ret;
 
-    /* Extract a few attributes */
+    /* Extract a device ID attribute */
     for (rta = RTM_RTA(rtmsg); RTA_OK(rta, len); rta = RTA_NEXT(rta, len)) {
-        switch (rta->rta_type) {
-        case RTA_OIF:
+        if (rta->rta_type == RTA_OIF) {
             oif = *(int *)RTA_DATA(rta);
 
+            /* Should never happen: netlink message would be broken */
+            if (ifname)
+                goto error;
+
             if (!(ifname = virNetDevGetName(oif)))
                 goto error;
-            break;
         }
     }
 
-- 
2.12.0




More information about the libvir-list mailing list