You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2010/06/30 18:22:07 UTC

svn commit: r959366 - /trafficserver/traffic/trunk/proxy/mgmt2/tools/SysAPI.cc

Author: zwoop
Date: Wed Jun 30 16:22:07 2010
New Revision: 959366

URL: http://svn.apache.org/viewvc?rev=959366&view=rev
Log:
TS-109: Segfault when using show:network

Tested: FC13

Modified:
    trafficserver/traffic/trunk/proxy/mgmt2/tools/SysAPI.cc

Modified: trafficserver/traffic/trunk/proxy/mgmt2/tools/SysAPI.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/mgmt2/tools/SysAPI.cc?rev=959366&r1=959365&r2=959366&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/mgmt2/tools/SysAPI.cc (original)
+++ trafficserver/traffic/trunk/proxy/mgmt2/tools/SysAPI.cc Wed Jun 30 16:22:07 2010
@@ -324,13 +324,15 @@ Net_GetNetworkIntCount()
   char buffer[200];
   int count = 0;
 
+  *buffer = '\0';
   // for each NIC
   net_device = fopen("/proc/net/dev", "r");
-
   while (!feof(net_device)) {
-    NOWARN_UNUSED_RETURN(fgets(buffer, 200, net_device));
-    if (strstr(buffer, "eth"))  // only counts eth interface
-      count++;
+    if (fgets(buffer, 200, net_device)) {
+      if (*buffer && strstr(buffer, "eth")) {  // only counts eth interface
+        count++;
+      }
+    }
   }
   fclose(net_device);
   return count;
@@ -345,22 +347,24 @@ Net_GetNetworkInt(int int_num, char *int
   char buffer[200];
   int space_len;
   char *pos, *tmp;
+  int i = -1;
 
+  *buffer = '\0';
   net_device = fopen("/proc/net/dev", "r");
 
-  int i = 0;
-  while (!feof(net_device) && i < int_num) {
-    NOWARN_UNUSED_RETURN(fgets(buffer, 200, net_device));
-    if (strstr(buffer, "eth"))  // only counts the eth interface
-      i++;
+  while (!feof(net_device) && (i != int_num)) {
+    if (fgets(buffer, 200, net_device)) {
+      if (strstr(buffer, "eth"))  // only counts the eth interface
+        i++;
+    }
   }
   fclose(net_device);
-
-  if (i < int_num - 1)
+  if (!*buffer || (i != int_num))
     return -1;
 
   pos = strchr(buffer, ':');
-  *pos = '\0';
+  if (pos)
+    *pos = '\0';
   space_len = strspn(buffer, " ");
   tmp = buffer + space_len;