]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-snmp.c
CMake: Fix the comment about versions. [skip ci]
[tcpdump] / print-snmp.c
index 03e5c3b415ab63770c6883f61b32734c4edaf650..76f0bbacaf0b4871670f6d000475c1c43a44e6de 100644 (file)
 
 /* \summary: Simple Network Management Protocol (SNMP) printer */
 
-#ifdef HAVE_CONFIG_H
 #include <config.h>
-#endif
 
 #include "netdissect-stdinc.h"
 
 #include <stdio.h>
 #include <string.h>
+#include <limits.h>
 
 #ifdef USE_LIBSMI
 #include <smi.h>
@@ -430,7 +429,6 @@ asn1_parse(netdissect_options *ndo,
                ND_PRINT("[nothing to parse]");
                return -1;
        }
-       ND_TCHECK_1(p);
 
        /*
         * it would be nice to use a bit field, but you can't depend on them.
@@ -465,7 +463,6 @@ asn1_parse(netdissect_options *ndo,
                 * that won't fit in 32 bits.
                 */
                id = 0;
-               ND_TCHECK_1(p);
                while (GET_U_1(p) & ASN_BIT8) {
                        if (len < 1) {
                                ND_PRINT("[Xtagfield?]");
@@ -475,13 +472,11 @@ asn1_parse(netdissect_options *ndo,
                        len--;
                        hdr++;
                        p++;
-                       ND_TCHECK_1(p);
                }
                if (len < 1) {
                        ND_PRINT("[Xtagfield?]");
                        return -1;
                }
-               ND_TCHECK_1(p);
                elem->id = id = (id << 7) | GET_U_1(p);
                --len;
                ++hdr;
@@ -491,7 +486,6 @@ asn1_parse(netdissect_options *ndo,
                ND_PRINT("[no asnlen]");
                return -1;
        }
-       ND_TCHECK_1(p);
        elem->asnlen = GET_U_1(p);
        p++; len--; hdr++;
        if (elem->asnlen & ASN_BIT8) {
@@ -536,7 +530,7 @@ asn1_parse(netdissect_options *ndo,
                                break;
 
                        case INTEGER: {
-                               int32_t data;
+                               uint32_t data;
                                elem->type = BE_INT;
                                data = 0;
 
@@ -545,7 +539,7 @@ asn1_parse(netdissect_options *ndo,
                                        return -1;
                                }
                                if (GET_U_1(p) & ASN_BIT8)      /* negative */
-                                       data = -1;
+                                       data = UINT_MAX;
                                for (i = elem->asnlen; i != 0; p++, i--)
                                        data = (data << ASN_SHIFT8) | GET_U_1(p);
                                elem->data.integer = data;
@@ -748,7 +742,8 @@ asn1_print(netdissect_options *ndo,
                break;
 
        case BE_OID: {
-               int o = 0, first = -1;
+               int first = -1;
+               uint32_t o = 0;
 
                p = (const u_char *)elem->data.raw;
                i = asnlen;
@@ -771,7 +766,6 @@ asn1_print(netdissect_options *ndo,
                }
 
                for (; i != 0; p++, i--) {
-                       ND_TCHECK_1(p);
                        o = (o << ASN_SHIFT7) + (GET_U_1(p) & ~ASN_BIT8);
                        if (GET_U_1(p) & ASN_LONGLEN)
                                continue;
@@ -924,7 +918,6 @@ smi_decode_oid(netdissect_options *ndo,
        unsigned int firstval;
 
        for (*oidlen = 0; i != 0; p++, i--) {
-               ND_TCHECK_1(p);
                o = (o << ASN_SHIFT7) + (GET_U_1(p) & ~ASN_BIT8);
                if (GET_U_1(p) & ASN_LONGLEN)
                    continue;
@@ -948,10 +941,6 @@ smi_decode_oid(netdissect_options *ndo,
                o = 0;
        }
        return 0;
-
-trunc:
-       nd_print_trunc(ndo);
-       return -1;
 }
 
 static int smi_check_type(SmiBasetype basetype, int be)
@@ -1099,7 +1088,7 @@ smi_print_value(netdissect_options *ndo,
        }
 
        if (NOTIFY_CLASS(pduid) && smiNode->access < SMI_ACCESS_NOTIFY) {
-           ND_PRINT("[notNotifyable]");
+           ND_PRINT("[notNotifiable]");
        }
 
        if (READ_CLASS(pduid) && smiNode->access < SMI_ACCESS_READ_ONLY) {
@@ -1228,7 +1217,7 @@ varbind_print(netdissect_options *ndo,
               u_short pduid, const u_char *np, u_int length)
 {
        struct be elem;
-       int count = 0, ind;
+       int count = 0;
 #ifdef USE_LIBSMI
        SmiNode *smiNode = NULL;
 #endif
@@ -1248,7 +1237,7 @@ varbind_print(netdissect_options *ndo,
        length = elem.asnlen;
        np = (const u_char *)elem.data.raw;
 
-       for (ind = 1; length > 0; ind++) {
+       while (length) {
                const u_char *vbend;
                u_int vblength;
 
@@ -1391,7 +1380,6 @@ snmppdu_print(netdissect_options *ndo,
        np += count;
 
        varbind_print(ndo, pduid, np, length);
-       return;
 }
 
 /*
@@ -1482,7 +1470,6 @@ trappdu_print(netdissect_options *ndo,
        np += count;
 
        varbind_print(ndo, TRAP, np, length);
-       return;
 }
 
 /*