[ovs-dev] [PATCH 04/15] netdev-linux: Avoid fiddling with indeterminate data.
Ben Pfaff
blp at nicira.com
Wed Feb 10 19:30:27 UTC 2010
If we are using netlink to get stats and get_ifindex() fails, then for
an internal network device we will then swap around a bunch of
indeterminate (uninitialized) data values. That won't hurt anything--the
caller will still set them to all-1-bits due to the error--but it still
seems wrong. So this commit makes us give up immediately on error.
Found using Clang (http://clang-analyzer.llvm.org/).
---
lib/netdev-linux.c | 9 ++++-----
1 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c
index ccc3f84..8225b9c 100644
--- a/lib/netdev-linux.c
+++ b/lib/netdev-linux.c
@@ -1223,9 +1223,7 @@ netdev_linux_get_stats(const struct netdev *netdev_,
COVERAGE_INC(netdev_get_stats);
if (!(netdev_dev->cache_valid & VALID_IS_INTERNAL)) {
- netdev_dev->is_internal = !strcmp(netdev_get_type(netdev_),
- "tap");
-
+ netdev_dev->is_internal = !strcmp(netdev_get_type(netdev_), "tap");
if (!netdev_dev->is_internal) {
struct ethtool_drvinfo drvinfo;
@@ -1255,9 +1253,10 @@ netdev_linux_get_stats(const struct netdev *netdev_,
int ifindex;
error = get_ifindex(netdev_, &ifindex);
- if (!error) {
- error = get_stats_via_netlink(ifindex, collect_stats);
+ if (error) {
+ return error;
}
+ error = get_stats_via_netlink(ifindex, collect_stats);
} else {
error = get_stats_via_proc(netdev_get_name(netdev_), collect_stats);
}
--
1.6.6.1
More information about the dev
mailing list