As discussed today over IRC, here's 2 patches for consideration in
inclusion for the 5.[56].* upcoming releases.

Patch #1 is simple and just increases the shift variable allowing for 16
bits of index values instead of the previous 8 (which wrapped >256 on
some systems).

Patch #2 is a bit more complex and creates new integer based index API
for retrieving indexes and then ensure that they're < 2^SHIFT.  If
they're greater than that, they're dropped as invalid indexes and the
data isn't reported (which is better than a crash).

Please vote on both about whether they should be included into the
upcoming 5.5.2 and 5.6.2 releases.

-- 
Wes Hardaker
Please mail all replies to net-snmp-coders@lists.sourceforge.net
diff --git a/agent/mibgroup/host_res.h b/agent/mibgroup/host_res.h
index 3320d2d..cd65514 100644
--- a/agent/mibgroup/host_res.h
+++ b/agent/mibgroup/host_res.h
@@ -67,7 +67,7 @@
 #define	HRDEV_NVMEM	21
 
 #define	HRDEV_TYPE_MAX	22      /* one greater than largest device type */
-#define	HRDEV_TYPE_SHIFT  8
+#define	HRDEV_TYPE_SHIFT  16
 #define	HRDEV_TYPE_MASK 0xff
 
 typedef void    (*PFV) (void);
diff --git a/agent/mibgroup/host/hr_network.c b/agent/mibgroup/host/hr_network.c
index cab0746..e503cf2 100644
--- a/agent/mibgroup/host/hr_network.c
+++ b/agent/mibgroup/host/hr_network.c
@@ -193,21 +193,21 @@ var_hrnet(struct variable * vp,
 #if defined( USING_IF_MIB_IFTABLE_IFTABLE_DATA_ACCESS_MODULE )
 static char     HRN_name[16];
 static netsnmp_interface_entry *HRN_ifnet;
-#define M_Interface_Scan_Next(a, b, c, d)	Interface_Scan_Next(a, b, c, d)
+#define M_Interface_Scan_Next(a, b, c, d)     Interface_Scan_NextInt(a, b, c, d)
 #elif defined(hpux11)
 static char     HRN_name[MAX_PHYSADDR_LEN];
 static nmapi_phystat HRN_ifnet;
-#define M_Interface_Scan_Next(a, b, c, d)	Interface_Scan_Next(a, b, c)
+#define M_Interface_Scan_Next(a, b, c, d)     Interface_Scan_NextInt(a, b, c)
 #elif defined darwin
 static char     HRN_name[IFNAMSIZ];
 static struct if_msghdr HRN_ifnet;
-#define M_Interface_Scan_Next(a, b, c, d)	Interface_Scan_Next(a, b, c, d)
+#define M_Interface_Scan_Next(a, b, c, d)     Interface_Scan_NextInt(a, b, c, d)
 #else                           /* hpux11 */
 static char     HRN_name[16];
 #ifndef WIN32
 static struct ifnet HRN_ifnet;
 #endif /* WIN32 */
-#define M_Interface_Scan_Next(a, b, c, d)	Interface_Scan_Next(a, b, c, d)
+#define M_Interface_Scan_Next(a, b, c, d)     Interface_Scan_NextInt(a, b, c, d)
 #endif
 
 #ifdef hpux11
@@ -230,7 +230,7 @@ Init_HR_Network(void)
 int
 Get_Next_HR_Network(void)
 {
-short    HRN_index;
+int    HRN_index;
 #if !(defined(solaris2) || defined(darwin) || defined(WIN32))
     if (M_Interface_Scan_Next(&HRN_index, HRN_name, &HRN_ifnet, NULL) == 0)
         HRN_index = -1;
@@ -240,6 +240,12 @@ short    HRN_index;
     if (-1 == HRN_index)
         return HRN_index;
 
+    /* if the index is greater than the shift registery space, we'll
+       repeat values and crash so we silently drop interfaces greater
+       than what the shift registery size can handle. */
+    if (HRN_index > (1 << HRDEV_TYPE_SHIFT))
+        return -1;
+
     return (HRDEV_NETWORK << HRDEV_TYPE_SHIFT) + HRN_index;
 }
 
diff --git a/agent/mibgroup/if-mib/data_access/interface.c b/agent/mibgroup/if-mib/data_access/interface.c
index 298cfd4..08634e7 100644
--- a/agent/mibgroup/if-mib/data_access/interface.c
+++ b/agent/mibgroup/if-mib/data_access/interface.c
@@ -387,8 +387,23 @@ Interface_Scan_Init(void)
 }
 
 int
-Interface_Scan_Next(short *index, char *name, netsnmp_interface_entry **entry,
-                    void *dc)
+Interface_Scan_Next(short *Index,
+                    char *Name, netsnmp_interface_entry **entry, void *dummy)
+{
+    int returnIndex = 0;
+    int ret;
+    if (Index)
+        returnIndex = *Index;
+    
+    ret = Interface_Scan_NextInt(&returnIndex, Name, entry, dummy);
+    if (Index)
+        *Index = returnIndex;
+    return ret;
+}
+
+int
+Interface_Scan_NextInt(int *index, char *name, netsnmp_interface_entry **entry,
+                       void *dc)
 {
     netsnmp_interface_entry* e = NULL;
 
diff --git a/agent/mibgroup/mibII/interfaces.c b/agent/mibgroup/mibII/interfaces.c
index 6804895..835208d 100644
--- a/agent/mibgroup/mibII/interfaces.c
+++ b/agent/mibgroup/mibII/interfaces.c
@@ -724,6 +724,14 @@ Interface_Scan_Next(short *Index,
     return 0;
 }
 
+int
+Interface_Scan_NextInt(int *Index,
+                       char *Name,
+                       struct ifnet *Retifnet, struct in_ifaddr *Retin_ifaddr)
+{
+    return 0;
+}
+
 #else                           /* not USE_SYSCTL_IFLIST */
 
         /*********************
@@ -1841,6 +1849,23 @@ Interface_Scan_Next(short *Index,
                     char *Name,
                     struct ifnet *Retifnet, struct in_ifaddr *dummy)
 {
+    int returnIndex = 0;
+    int ret;
+    if (Index)
+        returnIndex = *Index;
+    
+    ret = Interface_Scan_NextInt(&returnIndex, Name, Retifnet, dummy);
+    if (Index)
+        *Index = returnIndex;
+    return ret;
+}
+    
+
+int
+Interface_Scan_NextInt(int *Index,
+                       char *Name,
+                       struct ifnet *Retifnet, struct in_ifaddr *dummy)
+{
     struct ifnet    ifnet;
     register char  *cp;
 
@@ -1930,7 +1955,23 @@ Interface_Index_By_Name(char *Name, int Len)
 #if defined(hpux11)
 
 int
-Interface_Scan_Next(short *Index, char *Name, nmapi_phystat * Retifnet)
+Interface_Scan_Next(short *Index,
+                    char *Name,
+                    nmapi_phystat *Retifnet)
+{
+    int returnIndex = 0;
+    int ret;
+    if (Index)
+        returnIndex = *Index;
+    
+    ret = Interface_Scan_NextInt(&returnIndex, Name, Retifnet);
+    if (Index)
+        *Index = returnIndex;
+    return ret;
+}
+
+int
+Interface_Scan_NextInt(int *Index, char *Name, nmapi_phystat * Retifnet)
 {
     static nmapi_phystat *if_ptr = (nmapi_phystat *) 0;
     int             count = Interface_Scan_Get_Count();
@@ -1972,6 +2013,22 @@ Interface_Scan_Next(short *Index,
                     char *Name,
                     struct ifnet *Retifnet, struct in_ifaddr *Retin_ifaddr)
 {
+    int returnIndex = 0;
+    int ret;
+    if (Index)
+        returnIndex = *Index;
+    
+    ret = Interface_Scan_NextInt(&returnIndex, Name, Retifnet, Retin_ifaddr);
+    if (Index)
+        *Index = returnIndex;
+    return ret;
+}
+
+int
+Interface_Scan_NextInt(int *Index,
+                       char *Name,
+                       struct ifnet *Retifnet, struct in_ifaddr *Retin_ifaddr)
+{
     struct ifnet    ifnet;
     struct in_ifaddr *ia, in_ifaddr;
     short           has_ipaddr = 0;
diff --git a/agent/mibgroup/mibII/interfaces.h b/agent/mibgroup/mibII/interfaces.h
index f1fe8c4..dfd9a96 100644
--- a/agent/mibgroup/mibII/interfaces.h
+++ b/agent/mibgroup/mibII/interfaces.h
@@ -47,9 +47,12 @@ config_require(mibII/var_route)
 #endif
 #if defined(hpux11)
      int             Interface_Scan_Next(short *, char *, nmapi_phystat *);
+     int             Interface_Scan_NextInt(Int *, char *, nmapi_phystat *);
 #else
      int             Interface_Scan_Next(short *, char *, struct ifnet *,
                                          struct in_ifaddr *);
+     int             Interface_Scan_NextInt(Int *, char *, struct ifnet *,
+                                            struct in_ifaddr *);
 #endif
 
      void            init_interfaces(void);
diff --git a/include/net-snmp/data_access/interface.h b/include/net-snmp/data_access/interface.h
index dfc617f..baaa25d 100644
--- a/include/net-snmp/data_access/interface.h
+++ b/include/net-snmp/data_access/interface.h
@@ -292,6 +292,9 @@ Interface_Scan_Init(void);
 int
 Interface_Scan_Next(short *index, char *name, netsnmp_interface_entry **entry,
                     void *dc);
+int
+Interface_Scan_NextInt(int *index, char *name, netsnmp_interface_entry **entry,
+                       void *dc);
 #endif
 
 /**---------------------------------------------------------------------*/
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Net-snmp-coders mailing list
Net-snmp-coders@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to