Blame SOURCES/net-snmp-5.7.2-trap-vartypes.patch

34d7f3
commit 7f4a7b891332899cea26e95be0337aae01648742
34d7f3
Author: Jan Safranek <jsafranek@users.sourceforge.net>
34d7f3
Date:   Thu Jul 31 13:46:49 2014 +0200
34d7f3
34d7f3
    Added checks for printing variables with wrong types.
34d7f3
    
34d7f3
    When -OQ command line argument is used, variable formatter preffers the type
34d7f3
    of the varible parsed from a MIB file instead of checking type of the variable
34d7f3
    as parsed from SNMP message.
34d7f3
    
34d7f3
    This can lead to crashes when incoming packets contains a variable with
34d7f3
    NULL type, while the MIB says the variable should be non-NULL, like Integer.
34d7f3
    The formatter then tries to interpret the NULL (from packet) as Integer (from
34d7f3
    MIB file).
34d7f3
34d7f3
diff --git a/snmplib/mib.c b/snmplib/mib.c
34d7f3
index 9d3ca41..c6e0010 100644
34d7f3
--- a/snmplib/mib.c
34d7f3
+++ b/snmplib/mib.c
34d7f3
@@ -439,17 +439,16 @@ sprint_realloc_octet_string(u_char ** buf, size_t * buf_len,
34d7f3
     u_char         *cp;
34d7f3
     int             output_format, cnt;
34d7f3
 
34d7f3
-    if ((var->type != ASN_OCTET_STR) && 
34d7f3
-        (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT))) {
34d7f3
-        const char      str[] = "Wrong Type (should be OCTET STRING): ";
34d7f3
-        if (snmp_cstrcat
34d7f3
-            (buf, buf_len, out_len, allow_realloc, str)) {
34d7f3
-            return sprint_realloc_by_type(buf, buf_len, out_len,
34d7f3
+    if (var->type != ASN_OCTET_STR) {
34d7f3
+        if (!netsnmp_ds_get_boolean(
34d7f3
+                    NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT)) {
34d7f3
+            const char      str[] = "Wrong Type (should be OCTET STRING): ";
34d7f3
+            if (!snmp_cstrcat(buf, buf_len, out_len, allow_realloc, str))
34d7f3
+                return 0;
34d7f3
+        }
34d7f3
+        return sprint_realloc_by_type(buf, buf_len, out_len,
34d7f3
                                           allow_realloc, var, NULL, NULL,
34d7f3
                                           NULL);
34d7f3
-        } else {
34d7f3
-            return 0;
34d7f3
-        }
34d7f3
     }
34d7f3
 
34d7f3
 
34d7f3
@@ -702,16 +701,16 @@ sprint_realloc_float(u_char ** buf, size_t * buf_len,
34d7f3
                      const struct enum_list *enums,
34d7f3
                      const char *hint, const char *units)
34d7f3
 {
34d7f3
-    if ((var->type != ASN_OPAQUE_FLOAT) &&
34d7f3
-        (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT))) {
34d7f3
-        if (snmp_cstrcat(buf, buf_len, out_len, allow_realloc, 
34d7f3
-                         "Wrong Type (should be Float): ")) {
34d7f3
-            return sprint_realloc_by_type(buf, buf_len, out_len,
34d7f3
+    if (var->type != ASN_OPAQUE_FLOAT) {
34d7f3
+        if (!netsnmp_ds_get_boolean(
34d7f3
+                NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT)) {
34d7f3
+            u_char          str[] = "Wrong Type (should be Float): ";
34d7f3
+            if (!snmp_strcat(buf, buf_len, out_len, allow_realloc, str))
34d7f3
+                return 0;
34d7f3
+        }
34d7f3
+        return sprint_realloc_by_type(buf, buf_len, out_len,
34d7f3
                                           allow_realloc, var, NULL, NULL,
34d7f3
                                           NULL);
34d7f3
-        } else {
34d7f3
-            return 0;
34d7f3
-        }
34d7f3
     }
34d7f3
 
34d7f3
     if (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICK_PRINT)) {
34d7f3
@@ -772,17 +771,16 @@ sprint_realloc_double(u_char ** buf, size_t * buf_len,
34d7f3
                       const struct enum_list *enums,
34d7f3
                       const char *hint, const char *units)
34d7f3
 {
34d7f3
-    if ((var->type != ASN_OPAQUE_DOUBLE) && 
34d7f3
-        (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT))) {
34d7f3
-        if (snmp_cstrcat
34d7f3
-            (buf, buf_len, out_len, allow_realloc, 
34d7f3
-             "Wrong Type (should be Double): ")) {
34d7f3
-            return sprint_realloc_by_type(buf, buf_len, out_len,
34d7f3
+    if (var->type != ASN_OPAQUE_DOUBLE) {
34d7f3
+        if (!netsnmp_ds_get_boolean(
34d7f3
+                NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT)) {
34d7f3
+            u_char          str[] = "Wrong Type (should be Double): ";
34d7f3
+            if (!snmp_strcat(buf, buf_len, out_len, allow_realloc, str))
34d7f3
+                return 0;
34d7f3
+        }
34d7f3
+        return sprint_realloc_by_type(buf, buf_len, out_len,
34d7f3
                                           allow_realloc, var, NULL, NULL,
34d7f3
                                           NULL);
34d7f3
-        } else {
34d7f3
-            return 0;
34d7f3
-        }
34d7f3
     }
34d7f3
 
34d7f3
     if (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICK_PRINT)) {
34d7f3
@@ -847,20 +845,21 @@ sprint_realloc_counter64(u_char ** buf, size_t * buf_len, size_t * out_len,
34d7f3
 {
34d7f3
     char            a64buf[I64CHARSZ + 1];
34d7f3
 
34d7f3
-    if ((var->type != ASN_COUNTER64
34d7f3
+    if (var->type != ASN_COUNTER64
34d7f3
 #ifdef NETSNMP_WITH_OPAQUE_SPECIAL_TYPES
34d7f3
         && var->type != ASN_OPAQUE_COUNTER64
34d7f3
         && var->type != ASN_OPAQUE_I64 && var->type != ASN_OPAQUE_U64
34d7f3
 #endif
34d7f3
-        ) && (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT))) {
34d7f3
-        if (snmp_cstrcat(buf, buf_len, out_len, allow_realloc, 
34d7f3
-                        "Wrong Type (should be Counter64): ")) {
34d7f3
-            return sprint_realloc_by_type(buf, buf_len, out_len,
34d7f3
+        ) {
34d7f3
+        if (!netsnmp_ds_get_boolean(
34d7f3
+                NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT)) {
34d7f3
+            u_char          str[] = "Wrong Type (should be Counter64): ";
34d7f3
+            if (!snmp_strcat(buf, buf_len, out_len, allow_realloc, str))
34d7f3
+                return 0;
34d7f3
+        }
34d7f3
+        return sprint_realloc_by_type(buf, buf_len, out_len,
34d7f3
                                           allow_realloc, var, NULL, NULL,
34d7f3
                                           NULL);
34d7f3
-        } else {
34d7f3
-            return 0;
34d7f3
-        }
34d7f3
     }
34d7f3
 
34d7f3
     if (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICK_PRINT)) {
34d7f3
@@ -948,23 +947,25 @@ sprint_realloc_opaque(u_char ** buf, size_t * buf_len,
34d7f3
                       const struct enum_list *enums,
34d7f3
                       const char *hint, const char *units)
34d7f3
 {
34d7f3
-    if ((var->type != ASN_OPAQUE
34d7f3
+    if (var->type != ASN_OPAQUE
34d7f3
 #ifdef NETSNMP_WITH_OPAQUE_SPECIAL_TYPES
34d7f3
         && var->type != ASN_OPAQUE_COUNTER64
34d7f3
         && var->type != ASN_OPAQUE_U64
34d7f3
         && var->type != ASN_OPAQUE_I64
34d7f3
         && var->type != ASN_OPAQUE_FLOAT && var->type != ASN_OPAQUE_DOUBLE
34d7f3
 #endif                          /* NETSNMP_WITH_OPAQUE_SPECIAL_TYPES */
34d7f3
-        ) && (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT))) {
34d7f3
-        if (snmp_cstrcat(buf, buf_len, out_len, allow_realloc, 
34d7f3
-                         "Wrong Type (should be Opaque): ")) {
34d7f3
-            return sprint_realloc_by_type(buf, buf_len, out_len,
34d7f3
+        ) {
34d7f3
+        if (!netsnmp_ds_get_boolean(
34d7f3
+                NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT)) {
34d7f3
+            u_char          str[] = "Wrong Type (should be Opaque): ";
34d7f3
+            if (!snmp_strcat(buf, buf_len, out_len, allow_realloc, str))
34d7f3
+                return 0;
34d7f3
+        }
34d7f3
+        return sprint_realloc_by_type(buf, buf_len, out_len,
34d7f3
                                           allow_realloc, var, NULL, NULL,
34d7f3
                                           NULL);
34d7f3
-        } else {
34d7f3
-            return 0;
34d7f3
-        }
34d7f3
     }
34d7f3
+
34d7f3
 #ifdef NETSNMP_WITH_OPAQUE_SPECIAL_TYPES
34d7f3
     switch (var->type) {
34d7f3
     case ASN_OPAQUE_COUNTER64:
34d7f3
@@ -1040,17 +1041,16 @@ sprint_realloc_object_identifier(u_char ** buf, size_t * buf_len,
34d7f3
 {
34d7f3
     int             buf_overflow = 0;
34d7f3
 
34d7f3
-    if ((var->type != ASN_OBJECT_ID) &&
34d7f3
-        (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT))) {
34d7f3
-        u_char          str[] =
34d7f3
-            "Wrong Type (should be OBJECT IDENTIFIER): ";
34d7f3
-        if (snmp_strcat(buf, buf_len, out_len, allow_realloc, str)) {
34d7f3
-            return sprint_realloc_by_type(buf, buf_len, out_len,
34d7f3
+    if (var->type != ASN_OBJECT_ID) {
34d7f3
+        if (!netsnmp_ds_get_boolean(
34d7f3
+                NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT)) {
34d7f3
+            u_char          str[] = "Wrong Type (should be OBJECT IDENTIFIER): ";
34d7f3
+            if (!snmp_strcat(buf, buf_len, out_len, allow_realloc, str))
34d7f3
+                return 0;
34d7f3
+        }
34d7f3
+        return sprint_realloc_by_type(buf, buf_len, out_len,
34d7f3
                                           allow_realloc, var, NULL, NULL,
34d7f3
                                           NULL);
34d7f3
-        } else {
34d7f3
-            return 0;
34d7f3
-        }
34d7f3
     }
34d7f3
 
34d7f3
     if (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICK_PRINT)) {
34d7f3
@@ -1110,16 +1110,16 @@ sprint_realloc_timeticks(u_char ** buf, size_t * buf_len, size_t * out_len,
34d7f3
 {
34d7f3
     char            timebuf[40];
34d7f3
 
34d7f3
-    if ((var->type != ASN_TIMETICKS) && 
34d7f3
-        (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT))) {
34d7f3
-        u_char          str[] = "Wrong Type (should be Timeticks): ";
34d7f3
-        if (snmp_strcat(buf, buf_len, out_len, allow_realloc, str)) {
34d7f3
-            return sprint_realloc_by_type(buf, buf_len, out_len,
34d7f3
+    if (var->type != ASN_TIMETICKS) {
34d7f3
+        if (!netsnmp_ds_get_boolean(
34d7f3
+                NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT)) {
34d7f3
+            u_char          str[] = "Wrong Type (should be Timeticks): ";
34d7f3
+            if (!snmp_strcat(buf, buf_len, out_len, allow_realloc, str))
34d7f3
+                return 0;
34d7f3
+        }
34d7f3
+        return sprint_realloc_by_type(buf, buf_len, out_len,
34d7f3
                                           allow_realloc, var, NULL, NULL,
34d7f3
                                           NULL);
34d7f3
-        } else {
34d7f3
-            return 0;
34d7f3
-        }
34d7f3
     }
34d7f3
 
34d7f3
     if (netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_NUMERIC_TIMETICKS)) {
34d7f3
@@ -1277,17 +1277,18 @@ sprint_realloc_integer(u_char ** buf, size_t * buf_len, size_t * out_len,
34d7f3
 {
34d7f3
     char           *enum_string = NULL;
34d7f3
 
34d7f3
-    if ((var->type != ASN_INTEGER) && 
34d7f3
-        (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT))) {
34d7f3
-        u_char          str[] = "Wrong Type (should be INTEGER): ";
34d7f3
-        if (snmp_strcat(buf, buf_len, out_len, allow_realloc, str)) {
34d7f3
-            return sprint_realloc_by_type(buf, buf_len, out_len,
34d7f3
+    if (var->type != ASN_INTEGER) {
34d7f3
+        if (!netsnmp_ds_get_boolean(
34d7f3
+                NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT)) {
34d7f3
+            u_char          str[] = "Wrong Type (should be INTEGER): ";
34d7f3
+            if (!snmp_strcat(buf, buf_len, out_len, allow_realloc, str))
34d7f3
+                return 0;
34d7f3
+        }
34d7f3
+        return sprint_realloc_by_type(buf, buf_len, out_len,
34d7f3
                                           allow_realloc, var, NULL, NULL,
34d7f3
                                           NULL);
34d7f3
-        } else {
34d7f3
-            return 0;
34d7f3
-        }
34d7f3
     }
34d7f3
+
34d7f3
     for (; enums; enums = enums->next) {
34d7f3
         if (enums->value == *var->val.integer) {
34d7f3
             enum_string = enums->label;
34d7f3
@@ -1380,16 +1381,16 @@ sprint_realloc_uinteger(u_char ** buf, size_t * buf_len, size_t * out_len,
34d7f3
 {
34d7f3
     char           *enum_string = NULL;
34d7f3
 
34d7f3
-    if ((var->type != ASN_UINTEGER) && 
34d7f3
-        (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT))) {
34d7f3
-        u_char          str[] = "Wrong Type (should be UInteger32): ";
34d7f3
-        if (snmp_strcat(buf, buf_len, out_len, allow_realloc, str)) {
34d7f3
-            return sprint_realloc_by_type(buf, buf_len, out_len,
34d7f3
+    if (var->type != ASN_UINTEGER) {
34d7f3
+        if (!netsnmp_ds_get_boolean(
34d7f3
+                NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT)) {
34d7f3
+            u_char          str[] = "Wrong Type (should be UInteger32): ";
34d7f3
+            if (!snmp_strcat(buf, buf_len, out_len, allow_realloc, str))
34d7f3
+                return 0;
34d7f3
+        }
34d7f3
+        return sprint_realloc_by_type(buf, buf_len, out_len,
34d7f3
                                           allow_realloc, var, NULL, NULL,
34d7f3
                                           NULL);
34d7f3
-        } else {
34d7f3
-            return 0;
34d7f3
-        }
34d7f3
     }
34d7f3
 
34d7f3
     for (; enums; enums = enums->next) {
34d7f3
@@ -1477,17 +1478,16 @@ sprint_realloc_gauge(u_char ** buf, size_t * buf_len, size_t * out_len,
34d7f3
 {
34d7f3
     char            tmp[32];
34d7f3
 
34d7f3
-    if ((var->type != ASN_GAUGE) && 
34d7f3
-        (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT))) {
34d7f3
-        u_char          str[] =
34d7f3
-            "Wrong Type (should be Gauge32 or Unsigned32): ";
34d7f3
-        if (snmp_strcat(buf, buf_len, out_len, allow_realloc, str)) {
34d7f3
-            return sprint_realloc_by_type(buf, buf_len, out_len,
34d7f3
+    if (var->type != ASN_GAUGE) {
34d7f3
+        if (!netsnmp_ds_get_boolean(
34d7f3
+                NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT)) {
34d7f3
+            u_char          str[] = "Wrong Type (should be Gauge32 or Unsigned32): ";
34d7f3
+            if (!snmp_strcat(buf, buf_len, out_len, allow_realloc, str))
34d7f3
+                return 0;
34d7f3
+        }
34d7f3
+        return sprint_realloc_by_type(buf, buf_len, out_len,
34d7f3
                                           allow_realloc, var, NULL, NULL,
34d7f3
                                           NULL);
34d7f3
-        } else {
34d7f3
-            return 0;
34d7f3
-        }
34d7f3
     }
34d7f3
 
34d7f3
     if (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICK_PRINT)) {
34d7f3
@@ -1550,16 +1550,16 @@ sprint_realloc_counter(u_char ** buf, size_t * buf_len, size_t * out_len,
34d7f3
 {
34d7f3
     char            tmp[32];
34d7f3
 
34d7f3
-    if ((var->type != ASN_COUNTER) && 
34d7f3
-        (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT))) {
34d7f3
-        u_char          str[] = "Wrong Type (should be Counter32): ";
34d7f3
-        if (snmp_strcat(buf, buf_len, out_len, allow_realloc, str)) {
34d7f3
-            return sprint_realloc_by_type(buf, buf_len, out_len,
34d7f3
+    if (var->type != ASN_COUNTER) {
34d7f3
+        if (!netsnmp_ds_get_boolean(
34d7f3
+                NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT)) {
34d7f3
+            u_char          str[] = "Wrong Type (should be Counter32): ";
34d7f3
+            if (!snmp_strcat(buf, buf_len, out_len, allow_realloc, str))
34d7f3
+                return 0;
34d7f3
+        }
34d7f3
+        return sprint_realloc_by_type(buf, buf_len, out_len,
34d7f3
                                           allow_realloc, var, NULL, NULL,
34d7f3
                                           NULL);
34d7f3
-        } else {
34d7f3
-            return 0;
34d7f3
-        }
34d7f3
     }
34d7f3
 
34d7f3
     if (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICK_PRINT)) {
34d7f3
@@ -1613,16 +1613,16 @@ sprint_realloc_networkaddress(u_char ** buf, size_t * buf_len,
34d7f3
 {
34d7f3
     size_t          i;
34d7f3
 
34d7f3
-    if ((var->type != ASN_IPADDRESS) && 
34d7f3
-        (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT))) {
34d7f3
-        u_char          str[] = "Wrong Type (should be NetworkAddress): ";
34d7f3
-        if (snmp_strcat(buf, buf_len, out_len, allow_realloc, str)) {
34d7f3
-            return sprint_realloc_by_type(buf, buf_len, out_len,
34d7f3
+    if (var->type != ASN_IPADDRESS) {
34d7f3
+        if (!netsnmp_ds_get_boolean(
34d7f3
+                NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT)) {
34d7f3
+            u_char          str[] = "Wrong Type (should be NetworkAddress): ";
34d7f3
+            if (!snmp_strcat(buf, buf_len, out_len, allow_realloc, str))
34d7f3
+                return 0;
34d7f3
+        }
34d7f3
+        return sprint_realloc_by_type(buf, buf_len, out_len,
34d7f3
                                           allow_realloc, var, NULL, NULL,
34d7f3
                                           NULL);
34d7f3
-        } else {
34d7f3
-            return 0;
34d7f3
-        }
34d7f3
     }
34d7f3
 
34d7f3
     if (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICK_PRINT)) {
34d7f3
@@ -1679,16 +1679,16 @@ sprint_realloc_ipaddress(u_char ** buf, size_t * buf_len, size_t * out_len,
34d7f3
 {
34d7f3
     u_char         *ip = var->val.string;
34d7f3
 
34d7f3
-    if ((var->type != ASN_IPADDRESS) && 
34d7f3
-        (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT))) {
34d7f3
-        u_char          str[] = "Wrong Type (should be IpAddress): ";
34d7f3
-        if (snmp_strcat(buf, buf_len, out_len, allow_realloc, str)) {
34d7f3
-            return sprint_realloc_by_type(buf, buf_len, out_len,
34d7f3
+    if (var->type != ASN_IPADDRESS) {
34d7f3
+        if (!netsnmp_ds_get_boolean(
34d7f3
+                NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT)) {
34d7f3
+            u_char          str[] = "Wrong Type (should be IpAddress): ";
34d7f3
+            if (!snmp_strcat(buf, buf_len, out_len, allow_realloc, str))
34d7f3
+                return 0;
34d7f3
+        }
34d7f3
+        return sprint_realloc_by_type(buf, buf_len, out_len,
34d7f3
                                           allow_realloc, var, NULL, NULL,
34d7f3
                                           NULL);
34d7f3
-        } else {
34d7f3
-            return 0;
34d7f3
-        }
34d7f3
     }
34d7f3
 
34d7f3
     if (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICK_PRINT)) {
34d7f3
@@ -1737,20 +1737,20 @@ sprint_realloc_null(u_char ** buf, size_t * buf_len, size_t * out_len,
34d7f3
                     const struct enum_list *enums,
34d7f3
                     const char *hint, const char *units)
34d7f3
 {
34d7f3
-    if ((var->type != ASN_NULL) && 
34d7f3
-        (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT))) {
34d7f3
-        u_char          str[] = "Wrong Type (should be NULL): ";
34d7f3
-        if (snmp_strcat(buf, buf_len, out_len, allow_realloc, str)) {
34d7f3
-            return sprint_realloc_by_type(buf, buf_len, out_len,
34d7f3
+    if (var->type != ASN_NULL) {
34d7f3
+        if (!netsnmp_ds_get_boolean(
34d7f3
+                NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT)) {
34d7f3
+            u_char          str[] = "Wrong Type (should be NULL): ";
34d7f3
+            if (!snmp_strcat(buf, buf_len, out_len, allow_realloc, str))
34d7f3
+                return 0;
34d7f3
+        }
34d7f3
+        return sprint_realloc_by_type(buf, buf_len, out_len,
34d7f3
                                           allow_realloc, var, NULL, NULL,
34d7f3
                                           NULL);
34d7f3
-        } else {
34d7f3
-            return 0;
34d7f3
-        }
34d7f3
-    } else {
34d7f3
-        u_char          str[] = "NULL";
34d7f3
-        return snmp_strcat(buf, buf_len, out_len, allow_realloc, str);
34d7f3
     }
34d7f3
+
34d7f3
+    u_char          str[] = "NULL";
34d7f3
+    return snmp_strcat(buf, buf_len, out_len, allow_realloc, str);
34d7f3
 }
34d7f3
 
34d7f3
 
34d7f3
@@ -1785,16 +1785,16 @@ sprint_realloc_bitstring(u_char ** buf, size_t * buf_len, size_t * out_len,
34d7f3
     u_char         *cp;
34d7f3
     char           *enum_string;
34d7f3
 
34d7f3
-    if ((var->type != ASN_BIT_STR && var->type != ASN_OCTET_STR) &&
34d7f3
-        (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT))) {
34d7f3
-        u_char          str[] = "Wrong Type (should be BITS): ";
34d7f3
-        if (snmp_strcat(buf, buf_len, out_len, allow_realloc, str)) {
34d7f3
-            return sprint_realloc_by_type(buf, buf_len, out_len,
34d7f3
+    if (var->type != ASN_BIT_STR && var->type != ASN_OCTET_STR) {
34d7f3
+        if (!netsnmp_ds_get_boolean(
34d7f3
+                NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT)) {
34d7f3
+            u_char          str[] = "Wrong Type (should be BITS): ";
34d7f3
+            if (!snmp_strcat(buf, buf_len, out_len, allow_realloc, str))
34d7f3
+                return 0;
34d7f3
+        }
34d7f3
+        return sprint_realloc_by_type(buf, buf_len, out_len,
34d7f3
                                           allow_realloc, var, NULL, NULL,
34d7f3
                                           NULL);
34d7f3
-        } else {
34d7f3
-            return 0;
34d7f3
-        }
34d7f3
     }
34d7f3
 
34d7f3
     if (netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICK_PRINT)) {
34d7f3
@@ -1869,16 +1869,16 @@ sprint_realloc_nsapaddress(u_char ** buf, size_t * buf_len,
34d7f3
                            const struct enum_list *enums, const char *hint,
34d7f3
                            const char *units)
34d7f3
 {
34d7f3
-    if ((var->type != ASN_NSAP) && 
34d7f3
-        (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT))) {
34d7f3
-        u_char          str[] = "Wrong Type (should be NsapAddress): ";
34d7f3
-        if (snmp_strcat(buf, buf_len, out_len, allow_realloc, str)) {
34d7f3
-            return sprint_realloc_by_type(buf, buf_len, out_len,
34d7f3
+    if (var->type != ASN_NSAP) {
34d7f3
+        if (!netsnmp_ds_get_boolean(
34d7f3
+                NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT)) {
34d7f3
+            u_char          str[] = "Wrong Type (should be NsapAddress): ";
34d7f3
+            if (!snmp_strcat(buf, buf_len, out_len, allow_realloc, str))
34d7f3
+                return 0;
34d7f3
+        }
34d7f3
+        return sprint_realloc_by_type(buf, buf_len, out_len,
34d7f3
                                           allow_realloc, var, NULL, NULL,
34d7f3
                                           NULL);
34d7f3
-        } else {
34d7f3
-            return 0;
34d7f3
-        }
34d7f3
     }
34d7f3
 
34d7f3
     if (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICK_PRINT)) {
34d7f3
34d7f3
commit 3da0c378b5cb1bbf35d05a6212a483abda84a201
34d7f3
Author: Niels Baggesen <nba@users.sourceforge.net>
34d7f3
Date:   Mon Sep 1 08:59:04 2014 +0200
34d7f3
34d7f3
    Fix commit 7f4a7b891332899cea26e95be0337aae01648742: dont mix code and declarations.
34d7f3
34d7f3
diff --git a/snmplib/mib.c b/snmplib/mib.c
34d7f3
index c6e0010..7dcf3d0 100644
34d7f3
--- a/snmplib/mib.c
34d7f3
+++ b/snmplib/mib.c
34d7f3
@@ -1737,6 +1737,8 @@ sprint_realloc_null(u_char ** buf, size_t * buf_len, size_t * out_len,
34d7f3
                     const struct enum_list *enums,
34d7f3
                     const char *hint, const char *units)
34d7f3
 {
34d7f3
+    u_char          str[] = "NULL";
34d7f3
+
34d7f3
     if (var->type != ASN_NULL) {
34d7f3
         if (!netsnmp_ds_get_boolean(
34d7f3
                 NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT)) {
34d7f3
@@ -1749,7 +1751,6 @@ sprint_realloc_null(u_char ** buf, size_t * buf_len, size_t * out_len,
34d7f3
                                           NULL);
34d7f3
     }
34d7f3
 
34d7f3
-    u_char          str[] = "NULL";
34d7f3
     return snmp_strcat(buf, buf_len, out_len, allow_realloc, str);
34d7f3
 }
34d7f3