]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: check for null ifname inside virNetDevBandwidthSet()
authorLaine Stump <laine@laine.org>
Tue, 24 Feb 2015 18:17:24 +0000 (13:17 -0500)
committerLaine Stump <laine@laine.org>
Wed, 25 Feb 2015 18:10:34 +0000 (13:10 -0500)
Previously this function relied on having ATTRIBUTE_NONNULL(1) in its
prototype rather than explicitly checking for a null
ifname. Unfortunately, ATTRIBUTE_NONNULL is just a hint to the
optimizer and code analyzers like Coverity, it doesn't actually check
anything at execution time, so the result was possible warnings from
Coverity, along with the possibility of null dereferences when ifname
wasn't available.

This patch removes the ATTRIBUTE_NONNULL from the prototype, and
checks ifname inside the function, logging an error if it's NULL (once
we've determined that the user really is trying to set a bandwidth).

src/util/virnetdevbandwidth.c
src/util/virnetdevbandwidth.h

index c8a90c85227b8feeeb2605ff159acfdeddf605d1..8041d526971084b5648fc52a889c9db54c9c00c2 100644 (file)
@@ -83,6 +83,13 @@ virNetDevBandwidthSet(const char *ifname,
         return -1;
     }
 
+    if (!ifname) {
+        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
+                       _("Unable to set bandwidth for interface because "
+                         "device name is unknown"));
+        return -1;
+    }
+
     virNetDevBandwidthClear(ifname);
 
     if (bandwidth->in && bandwidth->in->average) {
index de289dbe04b6e8ff4369b05a3572a3048c772371..efcf95af51bf3ee15bf02c134cd209f1de994675 100644 (file)
@@ -46,7 +46,7 @@ void virNetDevBandwidthFree(virNetDevBandwidthPtr def);
 int virNetDevBandwidthSet(const char *ifname,
                           virNetDevBandwidthPtr bandwidth,
                           bool hierarchical_class)
-    ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
+    ATTRIBUTE_RETURN_CHECK;
 int virNetDevBandwidthClear(const char *ifname);
 int virNetDevBandwidthCopy(virNetDevBandwidthPtr *dest,
                            const virNetDevBandwidth *src)