From: Francois-Xavier Le Bail Date: Sat, 2 Dec 2017 13:19:13 +0000 (+0100) Subject: Use more the EXTRACT_U_1() macro (43/n) X-Git-Tag: tcpdump-4.99-bp~1681 X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/61c422a88caefe986c2bc0a7f2f3028f696fa5cd Use more the EXTRACT_U_1() macro (43/n) In: if (... p[n] ...) ... --- diff --git a/print-babel.c b/print-babel.c index a3f540f8..49fb81de 100644 --- a/print-babel.c +++ b/print-babel.c @@ -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 diff --git a/print-bgp.c b/print-bgp.c index fffc226c..4c9992d0 100644 --- a/print-bgp.c +++ b/print-bgp.c @@ -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; } diff --git a/print-dvmrp.c b/print-dvmrp.c index 4c54f53c..c954e001 100644 --- a/print-dvmrp.c +++ b/print-dvmrp.c @@ -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)))); diff --git a/print-hncp.c b/print-hncp.c index f6168fa6..559c7032 100644 --- a/print-hncp.c +++ b/print-hncp.c @@ -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; } diff --git a/print-icmp6.c b/print-icmp6.c index 761b3779..4fc13898 100644 --- a/print-icmp6.c +++ b/print-icmp6.c @@ -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) { diff --git a/print-ip6opts.c b/print-ip6opts.c index 1d036a89..db0ddbc4 100644 --- a/print-ip6opts.c +++ b/print-ip6opts.c @@ -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)); } diff --git a/print-isakmp.c b/print-isakmp.c index af9532dd..e5563631 100644 --- a/print-isakmp.c +++ b/print-isakmp.c @@ -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; diff --git a/print-juniper.c b/print-juniper.c index bd36fd2f..e36b0a8f 100644 --- a/print-juniper.c +++ b/print-juniper.c @@ -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 diff --git a/print-mobility.c b/print-mobility.c index 33f4470b..d4a27b04 100644 --- a/print-mobility.c +++ b/print-mobility.c @@ -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) */ diff --git a/print-pim.c b/print-pim.c index 1167c0be..3c41d9f9 100644 --- a/print-pim.c +++ b/print-pim.c @@ -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))); diff --git a/print-radius.c b/print-radius.c index fe7bde92..5ce68d16 100644 --- a/print-radius.c +++ b/print-radius.c @@ -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; diff --git a/print-smb.c b/print-smb.c index 2f5074c2..0f0d9ceb 100644 --- a/print-smb.c +++ b/print-smb.c @@ -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, " ")); 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, " ")); - if (p[0] & 0x08) + if (EXTRACT_U_1(p) & 0x08) ND_PRINT((ndo, " ")); - if (p[0] & 0x04) + if (EXTRACT_U_1(p) & 0x04) ND_PRINT((ndo, " ")); - if (p[0] & 0x02) + if (EXTRACT_U_1(p) & 0x02) ND_PRINT((ndo, " ")); ND_PRINT((ndo, "\n")); p += 2; diff --git a/print-telnet.c b/print-telnet.c index e3782177..8ff527b4 100644 --- a/print-telnet.c +++ b/print-telnet.c @@ -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++; } diff --git a/print-vjc.c b/print-vjc.c index 597ba060..b5f88ab6 100644 --- a/print-vjc.c +++ b/print-vjc.c @@ -30,6 +30,7 @@ #include #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))); diff --git a/smbutil.c b/smbutil.c index c7ec75ed..9d4dac0d 100644 --- 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] = '.'; }