xentop: fix NULL pointer dereference
authorKeir Fraser <keir.fraser@citrix.com>
Thu, 20 May 2010 13:10:07 +0000 (14:10 +0100)
committerKeir Fraser <keir.fraser@citrix.com>
Thu, 20 May 2010 13:10:07 +0000 (14:10 +0100)
On my system, I'm getting SIGSEGVs in xentop because
xenstat_node_domain() is returning NULL.  Skip the loop if it does
rather than crashing.

Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
tools/xenstat/libxenstat/src/xenstat_linux.c

index c17423d3f3b5c6a75e639dd47282ea3e9f04afc5..1543fb21dec3917d5be0538d968d567caf5d1a1e 100644 (file)
@@ -292,20 +292,22 @@ int xenstat_collect_networks(xenstat_node * node)
 
                /* If the device parsed is network bridge and both tx & rx packets are zero, we are most */
                /* likely using bonding so we alter the configuration for dom0 to have bridge stats */
-               if ((strstr(iface, devBridge) != NULL) && (strstr(iface, devNoBridge) == NULL)) {
-                       domain = xenstat_node_domain(node, 0);
+               if ((strstr(iface, devBridge) != NULL) &&
+                   (strstr(iface, devNoBridge) == NULL) &&
+                   ((domain = xenstat_node_domain(node, 0)) != NULL)) {
                        for (i = 0; i < domain->num_networks; i++) {
-                               if ((domain->networks[i].id == 0) && (domain->networks[i].tbytes == 0)
-                                       && (domain->networks[i].rbytes == 0)) {
-                                               domain->networks[i].tbytes = txBytes;
-                                               domain->networks[i].tpackets = txPackets;
-                                               domain->networks[i].terrs = txErrs;
-                                               domain->networks[i].tdrop = txDrops;
-                                               domain->networks[i].rbytes = rxBytes;
-                                               domain->networks[i].rpackets = rxPackets;
-                                               domain->networks[i].rerrs = rxErrs;
-                                               domain->networks[i].rdrop = rxDrops;
-                               }
+                               if ((domain->networks[i].id != 0) ||
+                                   (domain->networks[i].tbytes != 0) ||
+                                   (domain->networks[i].rbytes != 0))
+                                       continue;
+                               domain->networks[i].tbytes = txBytes;
+                               domain->networks[i].tpackets = txPackets;
+                               domain->networks[i].terrs = txErrs;
+                               domain->networks[i].tdrop = txDrops;
+                               domain->networks[i].rbytes = rxBytes;
+                               domain->networks[i].rpackets = rxPackets;
+                               domain->networks[i].rerrs = rxErrs;
+                               domain->networks[i].rdrop = rxDrops;
                        }
                }
                else /* Otherwise we need to preserve old behaviour */