Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > 20db51d70e6b59a061db97ce9b89c771 > files > 103

net-snmp-5.3.2.2-14.el5.src.rpm

606874 - snmptranslate reports Unsigned32 as -1

Source: upstream, SVN rev. 17794

diff -up net-snmp-5.5/snmplib/parse.c.orig net-snmp-5.5/snmplib/parse.c
--- net-snmp-5.5/snmplib/parse.c.orig	2010-07-14 08:53:36.000000000 +0200
+++ net-snmp-5.5/snmplib/parse.c	2010-07-14 08:59:08.000000000 +0200
@@ -2223,12 +2223,12 @@ parse_ranges(FILE * fp, struct range_lis
             nexttype = get_token(fp, nexttoken, MAXTOKEN);
         else
             taken = 0;
-        high = low = strtol(nexttoken, NULL, 10);
+        high = low = strtoll(nexttoken, NULL, 10);
         nexttype = get_token(fp, nexttoken, MAXTOKEN);
         if (nexttype == RANGE) {
             nexttype = get_token(fp, nexttoken, MAXTOKEN);
             errno = 0;
-            high = strtol(nexttoken, NULL, 10);
+            high = strtoll(nexttoken, NULL, 10);
             if ( errno == ERANGE ) {
                 if (netsnmp_ds_get_int(NETSNMP_DS_LIBRARY_ID, 
                                        NETSNMP_DS_LIB_MIB_WARNINGS))
Index: net-snmp/snmplib/mib.c
===================================================================
--- net-snmp/snmplib/mib.c	(revision 17793)
+++ net-snmp/snmplib/mib.c	(revision 17794)
@@ -4715,11 +4715,30 @@
             if (!snmp_strcat(buf, buf_len, out_len, allow_realloc, " ("))
                 return 0;
             while (rp) {
-                if (rp->low == rp->high)
-                    sprintf(str, "%s%d", (first ? "" : " | "), rp->low );
-                else
-                    sprintf(str, "%s%d..%d", (first ? "" : " | "),
-                                              rp->low, rp->high);
+                switch (tp->type) {
+                case TYPE_INTEGER:
+                case TYPE_INTEGER32:
+                    if (rp->low == rp->high)
+                        sprintf(str, "%s%d", (first ? "" : " | "), rp->low );
+                    else
+                        sprintf(str, "%s%d..%d", (first ? "" : " | "),
+                                rp->low, rp->high);
+                    break;
+                case TYPE_UNSIGNED32:
+                case TYPE_OCTETSTR:
+                case TYPE_GAUGE:
+                case TYPE_UINTEGER:
+                    if (rp->low == rp->high)
+                        sprintf(str, "%s%u", (first ? "" : " | "),
+                                (unsigned)rp->low );
+                    else
+                        sprintf(str, "%s%u..%u", (first ? "" : " | "),
+                                (unsigned)rp->low, (unsigned)rp->high);
+                    break;
+                default:
+                    /* No other range types allowed */
+                    break;
+                }
                 if (!snmp_strcat(buf, buf_len, out_len, allow_realloc, str))
                     return 0;
                 if (first)
Index: net-snmp/snmplib/parse.c
===================================================================
--- net-snmp/snmplib/parse.c	(revision 17793)
+++ net-snmp/snmplib/parse.c	(revision 17794)
@@ -904,6 +904,32 @@
     free((char *) np);
 }
 
+static void
+print_range_value(FILE * fp, int type, struct range_list * rp)
+{
+    switch (type) {
+    case TYPE_INTEGER:
+    case TYPE_INTEGER32:
+        if (rp->low == rp->high)
+            fprintf(fp, "%d", rp->low);
+        else
+            fprintf(fp, "%d..%d", rp->low, rp->high);
+        break;
+    case TYPE_UNSIGNED32:
+    case TYPE_OCTETSTR:
+    case TYPE_GAUGE:
+    case TYPE_UINTEGER:
+        if (rp->low == rp->high)
+            fprintf(fp, "%u", (unsigned)rp->low);
+        else
+            fprintf(fp, "%u..%u", (unsigned)rp->low, (unsigned)rp->high);
+        break;
+    default:
+        /* No other range types allowed */
+        break;
+    }
+}
+
 #ifdef TEST
 static void
 print_nodes(FILE * fp, struct node *root)
@@ -927,10 +953,12 @@
             }
         }
         if (np->ranges) {
-            fprintf(fp, "  Ranges: \n");
+            fprintf(fp, "  Ranges: ");
             for (rp = np->ranges; rp; rp = rp->next) {
-                fprintf(fp, "    %d..%d\n", rp->low, rp->high);
+                fprintf(fp, "\n    ");
+                print_range_value(fp, np->type, rp);
             }
+            fprintf(fp, "\n");
         }
         if (np->indexes) {
             fprintf(fp, "  Indexes: \n");
@@ -5325,10 +5353,7 @@
             while (rp) {
                 if (rp != tp->ranges)
                     fprintf(f, " | ");
-                if (rp->low == rp->high)
-                    fprintf(f, "%d", rp->low);
-                else
-                    fprintf(f, "%d..%d", rp->low, rp->high);
+                print_range_value(f, tp->type, rp);
                 rp = rp->next;
             }
             fprintf(f, "\n");