changeset 2878:2e50876cc43d

* src/mibgroup/mibII/helpers.c (cyg_snmp_get_if): Rewrite it so that when passed if_num<=0 it will no longer go into a 2^32 iteration loop that walks through all of memory and then returns a rogue pointer * src/mibgroup/mibII/helpers.c (cyg_snmp_num_interfaces): Rewrite it to to use the same (simpler, more obviously correct) loop structure that cyg_snmp_get_if() now uses.
author jld
date Thu, 21 May 2009 15:06:02 +0000
parents 4c0c17eb1601
children c212b2328003
files packages/net/snmp/agent/current/ChangeLog packages/net/snmp/agent/current/src/mibgroup/mibII/helpers.c
diffstat 2 files changed, 29 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/packages/net/snmp/agent/current/ChangeLog
+++ b/packages/net/snmp/agent/current/ChangeLog
@@ -1,8 +1,20 @@
+2009-05-11      Grant Edwards   <grant.b.edwards@gmail.com>
+	
+	* src/mibgroup/mibII/helpers.c (cyg_snmp_get_if): Rewrite it so that
+	when passed if_num<=0 it will no longer go into a 2^32 iteration
+	loop that walks through all of memory and then returns a rogue
+	pointer
+
+	* src/mibgroup/mibII/helpers.c (cyg_snmp_num_interfaces): Rewrite
+	it to to use the same (simpler, more obviously correct) loop
+	structure that cyg_snmp_get_if() now uses.
+
+	
 2004-05-14	Matt Jerdonek	<maj1224@yahoo.com>
 
 	* src/mibgroup/mibII/helpers.c (cyg_snmp_num_interfaces): return
 	correct number of interfaces including the loopback interface.  
-	* src/mibgroup/mibII/helpers (cyg_snmp_get_if) increment the
+	* src/mibgroup/mibII/helpers.c (cyg_snmp_get_if): increment the
 	interface index properly.  
 	* src/mibgroup/mibII/interfaces.c (var_ifTable): Add case 
 	for IFT_PPP interface type.
@@ -490,7 +502,7 @@ 2000-05-31  Hugo Tyson  <hmt@cygnus.co.u
 // ####GPLCOPYRIGHTBEGIN####                                                
 // -------------------------------------------                              
 // This file is part of eCos, the Embedded Configurable Operating System.   
-// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2009 Free Software Foundation, Inc.
 //
 // This program is free software; you can redistribute it and/or modify     
 // it under the terms of the GNU General Public License as published by     
--- a/packages/net/snmp/agent/current/src/mibgroup/mibII/helpers.c
+++ b/packages/net/snmp/agent/current/src/mibgroup/mibII/helpers.c
@@ -1,6 +1,6 @@
 //=============================================================================
 //
-//      sntp.c
+//      helpers.c
 //
 //      Helper functions to access the interface information
 //
@@ -8,7 +8,7 @@
 // ####ECOSGPLCOPYRIGHTBEGIN####                                            
 // -------------------------------------------                              
 // This file is part of eCos, the Embedded Configurable Operating System.   
-// Copyright (C) 2003 Free Software Foundation, Inc.                        
+// Copyright (C) 2003, 2009 Free Software Foundation, Inc.                        
 //
 // eCos is free software; you can redistribute it and/or modify it under    
 // the terms of the GNU General Public License as published by the Free     
@@ -62,33 +62,24 @@
 extern struct ifaddr **ifnet_addrs;
 
 long cyg_snmp_num_interfaces(void) {
-  long long_ret=0;
-  int cnt = if_index - 1;
-  
-  while (cnt >= 0) {
-    if (ifnet_addrs[cnt] != 0) {
-      long_ret++;
-    }
-    cnt--;
-  }
-  return long_ret;
+  int i,n=0;
+
+  for (i=0; i<if_index; ++i)
+    if (ifnet_addrs[i])
+      ++n;
+
+  return n;
 }
 
 struct ifnet *cyg_snmp_get_if(int if_num) {
-  int index = 0;
-  struct ifnet *ifp;
-  
-  do {
-    while(0 == ifnet_addrs[index])
-      index++;
+  int i,n=0;
 
-    ifp = ifnet_addrs[index]->ifa_ifp;
-    
-    if_num--;	    
-    index++;
-  } while (if_num);
+  for (i=0; i<if_index; ++i)
+    if (ifnet_addrs[i])
+      if (++n == if_num)
+        return ifnet_addrs[i]->ifa_ifp;
 
-  return ifp;
+  return NULL;
 }
 #endif