]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Use more the EXTRACT_U_1() macro (43/n)
authorFrancois-Xavier Le Bail <[email protected]>
Sat, 2 Dec 2017 13:19:13 +0000 (14:19 +0100)
committerFrancois-Xavier Le Bail <[email protected]>
Sun, 3 Dec 2017 12:35:26 +0000 (13:35 +0100)
In: if (... p[n] ...) ...

15 files changed:
print-babel.c
print-bgp.c
print-dvmrp.c
print-hncp.c
print-icmp6.c
print-ip6opts.c
print-isakmp.c
print-juniper.c
print-mobility.c
print-pim.c
print-radius.c
print-smb.c
print-telnet.c
print-vjc.c
smbutil.c

index a3f540f802f7f8ff3e131b334f69133a4cec97f1..49fb81deae36751853f07682d31f37aa5a63e924 100644 (file)
@@ -367,7 +367,7 @@ babel_print_v2(netdissect_options *ndo,
         message = cp + 4 + i;
 
         ND_TCHECK_1(message);
-        if((type = message[0]) == MESSAGE_PAD1) {
+        if((type = EXTRACT_U_1(message)) == MESSAGE_PAD1) {
             ND_PRINT((ndo, ndo->ndo_vflag ? "\n\tPad 1" : " pad1"));
             i += 1;
             continue;
@@ -518,7 +518,7 @@ babel_print_v2(netdissect_options *ndo,
                        (EXTRACT_U_1(message + 3) & 0x3f) ? "/unknown" : "",
                        format_prefix(ndo, prefix, plen),
                        metric, seqno, format_interval_update(interval)));
-                if(message[3] & 0x80) {
+                if(EXTRACT_U_1(message + 3) & 0x80) {
                     if(message[2] == 1)
                         memcpy(v4_prefix, prefix, 16);
                     else
index fffc226c21296e693f1338f18f27801d91b1cf78..4c9992d09e97c2cba18888ebb202d61cecceed85 100644 (file)
@@ -1347,7 +1347,7 @@ bgp_attr_get_as_size(netdissect_options *ndo,
         /*
          * If we do not find a valid segment type, our guess might be wrong.
          */
-        if (tptr[0] < BGP_AS_SEG_TYPE_MIN || tptr[0] > BGP_AS_SEG_TYPE_MAX) {
+        if (EXTRACT_U_1(tptr) < BGP_AS_SEG_TYPE_MIN || EXTRACT_U_1(tptr) > BGP_AS_SEG_TYPE_MAX) {
             goto trunc;
         }
         ND_TCHECK(tptr[1]);
@@ -2860,7 +2860,7 @@ bgp_print(netdissect_options *ndo,
        while (p < ep) {
                if (!ND_TTEST_1(p))
                        break;
-               if (p[0] != 0xff) {
+               if (EXTRACT_U_1(p) != 0xff) {
                        p++;
                        continue;
                }
index 4c54f53c3b253fcb6d729fadff04c64e4adbf934..c954e001fee22a768a5f446f175d986dc165488a 100644 (file)
@@ -177,11 +177,11 @@ print_report(netdissect_options *ndo,
                ND_TCHECK_3(bp);
                mask = (uint32_t)0xff << 24 | bp[0] << 16 | bp[1] << 8 | bp[2];
                width = 1;
-               if (bp[0])
+               if (EXTRACT_U_1(bp))
                        width = 2;
-               if (bp[1])
+               if (EXTRACT_U_1(bp + 1))
                        width = 3;
-               if (bp[2])
+               if (EXTRACT_U_1(bp + 2))
                        width = 4;
 
                ND_PRINT((ndo, "\n\tMask %s", intoa(htonl(mask))));
index f6168fa6dde241f511ca5c089934230dc676318d..559c70320724ec99ba596025bfe41ef634d6a4ac 100644 (file)
@@ -614,7 +614,7 @@ hncp_print_rec(netdissect_options *ndo,
 
         case HNCP_DELEGATED_PREFIX: {
             int l;
-            if (bodylen < 9 || bodylen < 9 + (value[8] + 7) / 8) {
+            if (bodylen < 9 || bodylen < 9 + (EXTRACT_U_1(value + 8) + 7) / 8) {
                 ND_PRINT((ndo, " %s", istr));
                 break;
             }
@@ -725,7 +725,7 @@ hncp_print_rec(netdissect_options *ndo,
         case HNCP_ASSIGNED_PREFIX: {
             uint8_t prty;
             int l;
-            if (bodylen < 6 || bodylen < 6 + (value[5] + 7) / 8) {
+            if (bodylen < 6 || bodylen < 6 + (EXTRACT_U_1(value + 5) + 7) / 8) {
                 ND_PRINT((ndo, " %s", istr));
                 break;
             }
index 761b3779e6f2c75b9744ffa97626120b77be1f8e..4fc138985da1185b09fc7c41b7deca0649d2621f 100644 (file)
@@ -1491,10 +1491,10 @@ mldv2_query_print(netdissect_options *ndo, const u_char *bp, u_int len)
 
     if (ndo->ndo_vflag) {
         ND_TCHECK(bp[25]);
-       if (bp[24] & 0x08) {
+       if (EXTRACT_U_1(bp + 24) & 0x08) {
                ND_PRINT((ndo," sflag"));
        }
-       if (bp[24] & 0x07) {
+       if (EXTRACT_U_1(bp + 24) & 0x07) {
                ND_PRINT((ndo," robustness=%d", EXTRACT_U_1(bp + 24) & 0x07));
        }
        if (bp[25] < 128) {
index 1d036a893b268f9d7a5f594ff694a733f1a9f233..db0ddbc4978abd4360a0a24bea90245fe3e7adbb 100644 (file)
@@ -121,7 +121,7 @@ ip6_opt_print(netdissect_options *ndo, const u_char *bp, int len)
                ND_PRINT((ndo, "(rtalert: trunc)"));
                goto trunc;
            }
-           if (bp[i + 1] != IP6OPT_RTALERT_LEN - 2) {
+           if (EXTRACT_U_1(bp + i + 1) != IP6OPT_RTALERT_LEN - 2) {
                ND_PRINT((ndo, "(rtalert: invalid len %d)", EXTRACT_U_1(bp + i + 1)));
                goto trunc;
            }
@@ -132,7 +132,7 @@ ip6_opt_print(netdissect_options *ndo, const u_char *bp, int len)
                ND_PRINT((ndo, "(jumbo: trunc)"));
                goto trunc;
            }
-           if (bp[i + 1] != IP6OPT_JUMBO_LEN - 2) {
+           if (EXTRACT_U_1(bp + i + 1) != IP6OPT_JUMBO_LEN - 2) {
                ND_PRINT((ndo, "(jumbo: invalid len %d)", EXTRACT_U_1(bp + i + 1)));
                goto trunc;
            }
@@ -143,12 +143,12 @@ ip6_opt_print(netdissect_options *ndo, const u_char *bp, int len)
                ND_PRINT((ndo, "(homeaddr: trunc)"));
                goto trunc;
            }
-           if (bp[i + 1] < IP6OPT_HOMEADDR_MINLEN - 2) {
+           if (EXTRACT_U_1(bp + i + 1) < IP6OPT_HOMEADDR_MINLEN - 2) {
                ND_PRINT((ndo, "(homeaddr: invalid len %d)", EXTRACT_U_1(bp + i + 1)));
                goto trunc;
            }
            ND_PRINT((ndo, "(homeaddr: %s", ip6addr_string(ndo, bp + i + 2)));
-            if (bp[i + 1] > IP6OPT_HOMEADDR_MINLEN - 2) {
+            if (EXTRACT_U_1(bp + i + 1) > IP6OPT_HOMEADDR_MINLEN - 2) {
                ip6_sopt_print(ndo, bp + i + IP6OPT_HOMEADDR_MINLEN,
                                (optlen - IP6OPT_HOMEADDR_MINLEN));
            }
index af9532dd402005aa858134805b858c9edb523eb5..e55636318b071e9452563261561a156cb7d65666 100644 (file)
@@ -3096,7 +3096,7 @@ isakmp_rfc3948_print(netdissect_options *ndo,
                     const u_char *bp2)
 {
        ND_TCHECK(bp[0]);
-       if(length == 1 && bp[0]==0xff) {
+       if(length == 1 && EXTRACT_U_1(bp)==0xff) {
                ND_PRINT((ndo, "isakmp-nat-keep-alive"));
                return;
        }
@@ -3109,7 +3109,8 @@ isakmp_rfc3948_print(netdissect_options *ndo,
        /*
         * see if this is an IKE packet
         */
-       if(bp[0]==0 && bp[1]==0 && bp[2]==0 && bp[3]==0) {
+       if (EXTRACT_U_1(bp) == 0 && EXTRACT_U_1(bp + 1) == 0 &&
+           EXTRACT_U_1(bp + 2) == 0 && EXTRACT_U_1(bp + 3) == 0) {
                ND_PRINT((ndo, "NONESP-encap: "));
                isakmp_print(ndo, bp+4, length-4, bp2);
                return;
index bd36fd2fe0f9103556b2d3239fecb4fe8552fbd8..e36b0a8f970e25838fa42c29f23a260e0058982a 100644 (file)
@@ -974,7 +974,7 @@ juniper_atm1_if_print(netdissect_options *ndo,
                 return l2info.header_len;
         }
 
-        if (p[0] == 0x03) { /* Cisco style NLPID encaps ? */
+        if (EXTRACT_U_1(p) == 0x03) { /* Cisco style NLPID encaps ? */
             isoclns_print(ndo, p + 1, l2info.length - 1);
             /* FIXME check if frame was recognized */
             return l2info.header_len;
@@ -1034,7 +1034,7 @@ juniper_atm2_if_print(netdissect_options *ndo,
             return l2info.header_len;
         }
 
-        if (p[0] == 0x03) { /* Cisco style NLPID encaps ? */
+        if (EXTRACT_U_1(p) == 0x03) { /* Cisco style NLPID encaps ? */
             isoclns_print(ndo, p + 1, l2info.length - 1);
             /* FIXME check if frame was recognized */
             return l2info.header_len;
@@ -1342,7 +1342,7 @@ juniper_parse_header(netdissect_options *ndo,
 #ifdef DLT_JUNIPER_MFR
             /* MFR child links don't carry cookies */
             if (l2info->pictype == DLT_JUNIPER_MFR &&
-                (p[0] & MFR_BE_MASK) == MFR_BE_MASK) {
+                (EXTRACT_U_1(p) & MFR_BE_MASK) == MFR_BE_MASK) {
                 l2info->cookie_len = 0;
             }
 #endif
index 33f4470b17f82d54048ace7133af60606c530661..d4a27b042f50c9ca240f9a80ea4f71f5ea96df3f 100644 (file)
@@ -282,15 +282,15 @@ mobility_print(netdissect_options *ndo,
                ND_PRINT((ndo, " seq#=%u", EXTRACT_BE_U_2(&mh->ip6m_data16[0])));
                hlen = IP6M_MINLEN;
                ND_TCHECK_2(bp + hlen);
-               if (bp[hlen] & 0xf0) {
+               if (EXTRACT_U_1(bp + hlen) & 0xf0) {
                        ND_PRINT((ndo, " "));
-                       if (bp[hlen] & 0x80)
+                       if (EXTRACT_U_1(bp + hlen) & 0x80)
                                ND_PRINT((ndo, "A"));
-                       if (bp[hlen] & 0x40)
+                       if (EXTRACT_U_1(bp + hlen) & 0x40)
                                ND_PRINT((ndo, "H"));
-                       if (bp[hlen] & 0x20)
+                       if (EXTRACT_U_1(bp + hlen) & 0x20)
                                ND_PRINT((ndo, "L"));
-                       if (bp[hlen] & 0x10)
+                       if (EXTRACT_U_1(bp + hlen) & 0x10)
                                ND_PRINT((ndo, "K"));
                }
                /* Reserved (4bits) */
index 1167c0bedb1beba78b351e2a244cc84f8224c7dc..3c41d9f94497d642885f9b808490f43ac1711385 100644 (file)
@@ -147,7 +147,7 @@ pimv1_join_prune_print(netdissect_options *ndo,
        int njp;
 
        /* If it's a single group and a single source, use 1-line output. */
-       if (ND_TTEST2(bp[0], 30) && bp[11] == 1 &&
+       if (ND_TTEST2(bp[0], 30) && EXTRACT_U_1(bp + 11) == 1 &&
            ((njoin = EXTRACT_BE_U_2(bp + 20)) + EXTRACT_BE_U_2(bp + 22)) == 1) {
                int hold;
 
@@ -326,7 +326,7 @@ pimv1_print(netdissect_options *ndo,
                break;
        }
        ND_TCHECK(bp[4]);
-       if ((bp[4] >> 4) != 1)
+       if ((EXTRACT_U_1(bp + 4) >> 4) != 1)
                ND_PRINT((ndo, " [v%d]", EXTRACT_U_1(bp + 4) >> 4));
        return;
 
@@ -417,7 +417,7 @@ cisco_autorp_print(netdissect_options *ndo,
                case 3: ND_PRINT((ndo, " PIMv1+2"));
                        break;
                }
-               if (bp[0] & 0xfc)
+               if (EXTRACT_U_1(bp) & 0xfc)
                        ND_PRINT((ndo, " [rsvd=0x%02x]", EXTRACT_U_1(bp) & 0xfc));
                bp += 1;
                len -= 1;
@@ -434,10 +434,10 @@ cisco_autorp_print(netdissect_options *ndo,
                        ND_TCHECK_6(bp);
                        ND_PRINT((ndo, "%c%s%s/%d", s, EXTRACT_U_1(bp) & 1 ? "!" : "",
                                  ipaddr_string(ndo, bp + 2), EXTRACT_U_1(bp + 1)));
-                       if (bp[0] & 0x02) {
+                       if (EXTRACT_U_1(bp) & 0x02) {
                                ND_PRINT((ndo, " bidir"));
                        }
-                       if (bp[0] & 0xfc) {
+                       if (EXTRACT_U_1(bp) & 0xfc) {
                                ND_PRINT((ndo, "[rsvd=0x%02x]", EXTRACT_U_1(bp) & 0xfc));
                        }
                        s = ',';
@@ -579,7 +579,7 @@ pimv2_addr_print(netdissect_options *ndo,
                default:
                        return -1;
                }
-               if (bp[1] != 0)
+               if (EXTRACT_U_1(bp + 1) != 0)
                        return -1;
                hdrlen = 2;
        } else {
@@ -621,18 +621,18 @@ pimv2_addr_print(netdissect_options *ndo,
                if (af == AF_INET) {
                        if (!silent) {
                                ND_PRINT((ndo, "%s", ipaddr_string(ndo, bp + 2)));
-                               if (bp[1] != 32)
+                               if (EXTRACT_U_1(bp + 1) != 32)
                                        ND_PRINT((ndo, "/%u", EXTRACT_U_1(bp + 1)));
                        }
                }
                else if (af == AF_INET6) {
                        if (!silent) {
                                ND_PRINT((ndo, "%s", ip6addr_string(ndo, bp + 2)));
-                               if (bp[1] != 128)
+                               if (EXTRACT_U_1(bp + 1) != 128)
                                        ND_PRINT((ndo, "/%u", EXTRACT_U_1(bp + 1)));
                        }
                }
-               if (bp[0] && !silent) {
+               if (EXTRACT_U_1(bp) && !silent) {
                        if (at == pimv2_group) {
                                ND_PRINT((ndo, "(0x%02x)", EXTRACT_U_1(bp)));
                        } else {
@@ -640,7 +640,7 @@ pimv2_addr_print(netdissect_options *ndo,
                                        EXTRACT_U_1(bp) & 0x04 ? "S" : "",
                                        EXTRACT_U_1(bp) & 0x02 ? "W" : "",
                                        EXTRACT_U_1(bp) & 0x01 ? "R" : ""));
-                               if (bp[0] & 0xf8) {
+                               if (EXTRACT_U_1(bp) & 0xf8) {
                                        ND_PRINT((ndo, "+0x%02x", EXTRACT_U_1(bp) & 0xf8));
                                }
                                ND_PRINT((ndo, ")"));
@@ -1109,7 +1109,7 @@ pimv2_print(netdissect_options *ndo,
                if (len < 8)
                        goto trunc;
                ND_TCHECK_8(bp);
-               if (bp[0] & 0x80)
+               if (EXTRACT_U_1(bp) & 0x80)
                        ND_PRINT((ndo, " RPT"));
                ND_PRINT((ndo, " pref=%u", EXTRACT_BE_U_4(bp) & 0x7fffffff));
                ND_PRINT((ndo, " metric=%u", EXTRACT_BE_U_4(bp + 4)));
index fe7bde9228439e57d549cb55b02d6633875e422c..5ce68d163cd8bff63cb80dd3c14e6754f73de602 100644 (file)
@@ -907,7 +907,7 @@ print_attr_netmask6(netdissect_options *ndo,
        return;
    }
    ND_TCHECK2(data[0], length);
-   if (data[1] > 128)
+   if (EXTRACT_U_1(data + 1) > 128)
    {
       ND_PRINT((ndo, "ERROR: netmask %u not in range (0..128)", EXTRACT_U_1(data + 1)));
       return;
@@ -919,7 +919,7 @@ print_attr_netmask6(netdissect_options *ndo,
 
    ND_PRINT((ndo, "%s/%u", ip6addr_string(ndo, data2), EXTRACT_U_1(data + 1)));
 
-   if (data[1] > 8 * (length - 2))
+   if (EXTRACT_U_1(data + 1) > 8 * (length - 2))
       ND_PRINT((ndo, " (inconsistent prefix length)"));
 
    return;
index 2f5074c2e09591ce2e073285dd0676dc1c690af0..0f0d9cebde3cd3559ddc4b74092c1a6a1a7f896c 100644 (file)
@@ -188,7 +188,7 @@ print_trans2(netdissect_options *ndo,
        data = buf + EXTRACT_LE_U_2(w + 12 * 2);
        fn = smbfindint(EXTRACT_LE_U_2(w + 14 * 2), trans2_fns);
     } else {
-       if (words[0] == 0) {
+       if (EXTRACT_U_1(words) == 0) {
            ND_PRINT((ndo, "%s\n", fn->name));
            ND_PRINT((ndo, "Trans2Interim\n"));
            return;
@@ -836,7 +836,7 @@ print_smb(netdissect_options *ndo,
        if (nterror)
            ND_PRINT((ndo, "NTError = %s\n", nt_errstr(nterror)));
     } else {
-       if (buf[5])
+       if (EXTRACT_U_1(buf + 5))
            ND_PRINT((ndo, "SMBError = %s\n", smb_errstr(EXTRACT_U_1(buf + 5),
                      EXTRACT_LE_U_2(buf + 7))));
     }
@@ -1198,7 +1198,7 @@ nbt_udp137_print(netdissect_options *ndo,
                        if (p == NULL)
                            goto out;
                        ND_TCHECK(*p);
-                       if (p[0] & 0x80)
+                       if (EXTRACT_U_1(p) & 0x80)
                            ND_PRINT((ndo, "<GROUP> "));
                        switch (p[0] & 0x60) {
                        case 0x00: ND_PRINT((ndo, "B ")); break;
@@ -1206,13 +1206,13 @@ nbt_udp137_print(netdissect_options *ndo,
                        case 0x40: ND_PRINT((ndo, "M ")); break;
                        case 0x60: ND_PRINT((ndo, "_ ")); break;
                        }
-                       if (p[0] & 0x10)
+                       if (EXTRACT_U_1(p) & 0x10)
                            ND_PRINT((ndo, "<DEREGISTERING> "));
-                       if (p[0] & 0x08)
+                       if (EXTRACT_U_1(p) & 0x08)
                            ND_PRINT((ndo, "<CONFLICT> "));
-                       if (p[0] & 0x04)
+                       if (EXTRACT_U_1(p) & 0x04)
                            ND_PRINT((ndo, "<ACTIVE> "));
-                       if (p[0] & 0x02)
+                       if (EXTRACT_U_1(p) & 0x02)
                            ND_PRINT((ndo, "<PERMANENT> "));
                        ND_PRINT((ndo, "\n"));
                        p += 2;
index e3782177a9f4c0534bb3759030479cf37ec51e74..8ff527b4849d1ca02b4fe7f00f48c8bc3815aa39 100644 (file)
@@ -439,7 +439,7 @@ telnet_parse(netdissect_options *ndo, const u_char *sp, u_int length, int print)
                p = sp;
                while (length > (u_int)(p + 1 - sp)) {
                        ND_TCHECK_2(p);
-                       if (p[0] == IAC && p[1] == SE)
+                       if (EXTRACT_U_1(p) == IAC && EXTRACT_U_1(p + 1) == SE)
                                break;
                        p++;
                }
index 597ba060456750dda87f4c91d377ea8f9a6e3df6..b5f88ab6d2cecc43d546656cccbf94e6ee8d85e2 100644 (file)
@@ -30,6 +30,7 @@
 #include <netdissect-stdinc.h>
 
 #include "netdissect.h"
+#include "extract.h"
 #include "slcompress.h"
 #include "ppp.h"
 
@@ -100,10 +101,10 @@ vjc_print(netdissect_options *ndo, register const u_char *bp, u_short proto _U_)
                if (ndo->ndo_eflag)
                        ND_PRINT((ndo, "(vjc type=compressed TCP) "));
                for (i = 0; i < 8; i++) {
-                       if (bp[1] & (0x80 >> i))
+                       if (EXTRACT_U_1(bp + 1) & (0x80 >> i))
                                ND_PRINT((ndo, "%c", "?CI?SAWU"[i]));
                }
-               if (bp[1])
+               if (EXTRACT_U_1(bp + 1))
                        ND_PRINT((ndo, " "));
                ND_PRINT((ndo, "C=0x%02x ", bp[2]));
                ND_PRINT((ndo, "sum=0x%04x ", *(const u_short *)(bp + 3)));
index c7ec75ed998ca4fb3a1b318c98591986cdc15477..9d4dac0d198dd53877f0af1e4c201aea665038ee 100644 (file)
--- a/smbutil.c
+++ b/smbutil.c
@@ -145,7 +145,8 @@ name_interpret(netdissect_options *ndo,
        ND_TCHECK_2(in);
        if (in + 1 >= maxbuf)
            return(-1); /* name goes past the end of the buffer */
-       if (in[0] < 'A' || in[0] > 'P' || in[1] < 'A' || in[1] > 'P') {
+       if (EXTRACT_U_1(in) < 'A' || EXTRACT_U_1(in) > 'P' ||
+           EXTRACT_U_1(in + 1) < 'A' || EXTRACT_U_1(in + 1) > 'P') {
            *out = 0;
            return(0);
        }
@@ -367,7 +368,7 @@ unistr(netdissect_options *ndo,
            for (;;) {
                ND_TCHECK(sp[0]);
                *len += 1;
-               if (sp[0] == 0)
+               if (EXTRACT_U_1(sp) == 0)
                    break;
                sp++;
            }
@@ -376,7 +377,7 @@ unistr(netdissect_options *ndo,
            for (;;) {
                ND_TCHECK_2(sp);
                *len += 2;
-               if (sp[0] == 0 && sp[1] == 0)
+               if (EXTRACT_U_1(sp) == 0 && EXTRACT_U_1(sp + 1) == 0)
                    break;
                sp += 2;
            }
@@ -396,7 +397,7 @@ unistr(netdissect_options *ndo,
            if (ND_ISPRINT(EXTRACT_U_1(s)))
                buf[l] = s[0];
            else {
-               if (s[0] == 0)
+               if (EXTRACT_U_1(s) == 0)
                    break;
                buf[l] = '.';
            }
@@ -414,7 +415,7 @@ unistr(netdissect_options *ndo,
                buf[l] = s[0];
            } else {
                /* It's a non-ASCII character or a non-printable ASCII character */
-               if (s[0] == 0 && s[1] == 0)
+               if (EXTRACT_U_1(s) == 0 && EXTRACT_U_1(s + 1) == 0)
                    break;
                buf[l] = '.';
            }