]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Squelch a Coverity warning.
authorGuy Harris <[email protected]>
Tue, 8 Jul 2014 10:23:09 +0000 (03:23 -0700)
committerGuy Harris <[email protected]>
Tue, 8 Jul 2014 10:23:09 +0000 (03:23 -0700)
If you pass in a value of oidlen and oidsize such that we can't store
*anything* into OID, this would be a problem; that *shouldn't* ever
happen, but this makes the code a bit more obviously correct.

print-snmp.c

index 40d559da4bbb91180fe4a4a0e9d27ccfc9f5948b..f38fff70ee3aa28135984de0f54d57068a825356 100644 (file)
@@ -898,6 +898,7 @@ smi_decode_oid(netdissect_options *ndo,
        u_char *p = (u_char *)elem->data.raw;
        uint32_t asnlen = elem->asnlen;
        int o = 0, first = -1, i = asnlen;
+       unsigned int firstval;
 
        for (*oidlen = 0; ndo->ndo_sflag && i-- > 0; p++) {
                ND_TCHECK(*p);
@@ -911,11 +912,12 @@ smi_decode_oid(netdissect_options *ndo,
                 */
                if (first < 0) {
                        first = 0;
+                       firstval = o / OIDMUX;
+                       if (firstval > 2) firstval = 2;
                        if (*oidlen < oidsize) {
-                           oid[*oidlen] = o / OIDMUX;
-                           if (oid[*oidlen] > 2) oid[*oidlen] = 2;
+                           oid[*oidlen] = firstval;
                        }
-                       o -= oid[*oidlen] * OIDMUX;
+                       o -= firstval * OIDMUX;
                        if (*oidlen < oidsize) (*oidlen)++;
                }
                if (*oidlen < oidsize) {