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 | 9 ++++++++- src/util/virnetdevbandwidth.h | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/util/virnetdevbandwidth.c b/src/util/virnetdevbandwidth.c index fbd2a8d..5de84a9 100644 --- a/src/util/virnetdevbandwidth.c +++ b/src/util/virnetdevbandwidth.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2014 Red Hat, Inc. + * Copyright (C) 2009-2015 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -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) { diff --git a/src/util/virnetdevbandwidth.h b/src/util/virnetdevbandwidth.h index 4606a07..9b8f514 100644 --- a/src/util/virnetdevbandwidth.h +++ b/src/util/virnetdevbandwidth.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2013 Red Hat, Inc. + * Copyright (C) 2009-2015 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -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) ATTRIBUTE_NONNULL(1); int virNetDevBandwidthCopy(virNetDevBandwidthPtr *dest, -- 2.1.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list