]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Remove some now redundant ND_TCHECK_4() calls
authorFrancois-Xavier Le Bail <[email protected]>
Sat, 5 Sep 2020 19:56:50 +0000 (21:56 +0200)
committerFrancois-Xavier Le Bail <[email protected]>
Tue, 8 Sep 2020 12:14:13 +0000 (14:14 +0200)
ND_TCHECK_4(e).

They are redundant because they are followed by a GET_IPADDR_STRING(e)
call, same e, which do the bounds check.

Remove unused 'trunc' labels and associated codes.

Update the output of a test accordingly.

16 files changed:
print-ahcp.c
print-bgp.c
print-bootp.c
print-cdp.c
print-dvmrp.c
print-hsrp.c
print-icmp.c
print-igmp.c
print-ip.c
print-lisp.c
print-openflow-1.0.c
print-ospf.c
print-ospf6.c
print-pim.c
print-ppp.c
tests/ip_printroute_asan.out

index 2a1eb1ab9ec719a62496c7dfce06a3b4aa0637b1..d5b2cc0d506a3f0f4a2924102b9ebc17e4928613 100644 (file)
@@ -171,7 +171,6 @@ ahcp_ipv4_addresses_print(netdissect_options *ndo, const u_char *cp, const u_cha
        while (cp < ep) {
                if (cp + 4 > ep)
                        goto invalid;
-               ND_TCHECK_4(cp);
                ND_PRINT("%s%s", sep, GET_IPADDR_STRING(cp));
                cp += 4;
                sep = ", ";
index 0abb7001fd35693263f6a905e5c57c6c3ee980b7..0e45ee3eda48511cfbbb6074bc052c24cfb6cc8c 100644 (file)
@@ -1980,7 +1980,6 @@ bgp_attr_print(netdissect_options *ndo,
         if (len != 4)
             ND_PRINT("invalid len");
         else {
-            ND_TCHECK_4(tptr);
             ND_PRINT("%s", GET_IPADDR_STRING(tptr));
         }
         break;
@@ -2063,7 +2062,6 @@ bgp_attr_print(netdissect_options *ndo,
             ND_PRINT("invalid len");
             break;
         }
-        ND_TCHECK_4(tptr);
         ND_PRINT("%s",GET_IPADDR_STRING(tptr));
         break;
     case BGPTYPE_CLUSTER_LIST:
@@ -2072,7 +2070,6 @@ bgp_attr_print(netdissect_options *ndo,
             break;
         }
         while (tlen != 0) {
-            ND_TCHECK_4(tptr);
             if (tlen < 4)
                 goto trunc;
             ND_PRINT("%s%s",
@@ -2382,7 +2379,6 @@ bgp_attr_print(netdissect_options *ndo,
                       GET_IPADDR_STRING(tptr+4));
             break;
         case BGP_PMSI_TUNNEL_INGRESS:
-            ND_TCHECK_4(tptr);
             ND_PRINT("\n\t      Tunnel-Endpoint %s",
                       GET_IPADDR_STRING(tptr));
             break;
index a2f1929a37b443733bcdf2b9d500e7f0917e7d65..1ee979f5d2e02ff05c31d07c5c1a070cf59efeb9 100644 (file)
@@ -322,22 +322,18 @@ bootp_print(netdissect_options *ndo,
                ND_PRINT(" (0x%04x)", GET_BE_U_2(bp->bp_flags));
 
        /* Client's ip address */
-       ND_TCHECK_4(bp->bp_ciaddr);
        if (GET_IPV4_TO_NETWORK_ORDER(bp->bp_ciaddr))
                ND_PRINT("\n\t  Client-IP %s", GET_IPADDR_STRING(bp->bp_ciaddr));
 
        /* 'your' ip address (bootp client) */
-       ND_TCHECK_4(bp->bp_yiaddr);
        if (GET_IPV4_TO_NETWORK_ORDER(bp->bp_yiaddr))
                ND_PRINT("\n\t  Your-IP %s", GET_IPADDR_STRING(bp->bp_yiaddr));
 
        /* Server's ip address */
-       ND_TCHECK_4(bp->bp_siaddr);
        if (GET_IPV4_TO_NETWORK_ORDER(bp->bp_siaddr))
                ND_PRINT("\n\t  Server-IP %s", GET_IPADDR_STRING(bp->bp_siaddr));
 
        /* Gateway's ip address */
-       ND_TCHECK_4(bp->bp_giaddr);
        if (GET_IPV4_TO_NETWORK_ORDER(bp->bp_giaddr))
                ND_PRINT("\n\t  Gateway-IP %s", GET_IPADDR_STRING(bp->bp_giaddr));
 
index e1e7d71b92185b3bb6bcd3605afce15effe033e4..0ab646e51dee71dd63296ee4bd1b9c80a58ac94a 100644 (file)
@@ -337,7 +337,6 @@ cdp_print_addr(netdissect_options *ndo,
                         */
                        p += 3;
 
-                       ND_TCHECK_4(p);
                        if (p + 4 > endp)
                                goto trunc;
                        ND_PRINT("IPv4 (%u) %s", num, GET_IPADDR_STRING(p));
index 8ed95a8d47ba5dc958f7adfb5839de4a223884fe..abda58fa57dfa8dc736a5764623a00803c6adc4b 100644 (file)
@@ -237,7 +237,6 @@ print_probe(netdissect_options *ndo,
                return (0);
 
        while ((len > 0) && (bp < ep)) {
-               ND_TCHECK_4(bp);
                ND_PRINT("\n\tneighbor %s", GET_IPADDR_STRING(bp));
                bp += 4; len -= 4;
        }
@@ -268,7 +267,6 @@ print_neighbors(netdissect_options *ndo,
                bp++;
                len -= 7;
                while (--ncount >= 0) {
-                       ND_TCHECK_4(bp);
                        ND_PRINT(" [%s ->", GET_IPADDR_STRING(laddr));
                        ND_PRINT(" %s, (%u/%u)]",
                                   GET_IPADDR_STRING(bp), metric, thresh);
index b4e02f5513659151643f869cf2cdfda7d0c35122..3b6a1ff8f1458f81b9fd5c07c56e1d6ee87d5e39 100644 (file)
@@ -114,7 +114,6 @@ hsrp_print(netdissect_options *ndo, const u_char *bp, u_int len)
        if (GET_U_1(hp->hsrp_reserved) != 0) {
                ND_PRINT("[reserved=%u!] ", GET_U_1(hp->hsrp_reserved));
        }
-       ND_TCHECK_4(hp->hsrp_virtaddr);
        ND_PRINT("addr=%s", GET_IPADDR_STRING(hp->hsrp_virtaddr));
        if (ndo->ndo_vflag) {
                ND_PRINT(" hellotime=");
index 020e433ee44496570be966fef06fbcb6ab338d63..59b56c6ab28fbad5de36d2a7ab0ed4416b01a99f 100644 (file)
@@ -333,7 +333,6 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char *
                break;
 
        case ICMP_UNREACH:
-               ND_TCHECK_4(dp->icmp_ip.ip_dst);
                switch (icmp_code) {
 
                case ICMP_UNREACH_NET:
@@ -481,7 +480,6 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char *
                break;
 
        case ICMP_REDIRECT:
-               ND_TCHECK_4(dp->icmp_ip.ip_dst);
                switch (icmp_code) {
 
                case ICMP_REDIRECT_NET:
index 2c83fb8a11ce6827fbd82bbef7d0f3dcb6f52270..8c5bc15d59ebde0270f618b64cbc3b5502af0909 100644 (file)
@@ -288,13 +288,11 @@ igmp_print(netdissect_options *ndo,
        }
         break;
     case 0x12:
-        ND_TCHECK_4(bp + 4);
         ND_PRINT("igmp v1 report %s", GET_IPADDR_STRING(bp + 4));
         if (len != 8)
             ND_PRINT(" [len %u]", len);
         break;
     case 0x16:
-        ND_TCHECK_4(bp + 4);
         ND_PRINT("igmp v2 report %s", GET_IPADDR_STRING(bp + 4));
         break;
     case 0x22:
@@ -302,7 +300,6 @@ igmp_print(netdissect_options *ndo,
        print_igmpv3_report(ndo, bp, len);
         break;
     case 0x17:
-        ND_TCHECK_4(bp + 4);
         ND_PRINT("igmp leave %s", GET_IPADDR_STRING(bp + 4));
         break;
     case 0x13:
@@ -334,7 +331,4 @@ igmp_print(netdissect_options *ndo,
         if (in_cksum(vec, 1))
             ND_PRINT(" bad igmp cksum %x!", GET_BE_U_2(bp + 2));
     }
-    return;
-trunc:
-    nd_print_trunc(ndo);
 }
index 47850f3130461f8d8c246bd023135fb4d1a4f459..8dab94437e6919924dc23b1ac3c8de30375bd634 100644 (file)
@@ -71,15 +71,11 @@ ip_printroute(netdissect_options *ndo,
                ND_PRINT(" [bad ptr %u]", GET_U_1(cp + 2));
 
        for (len = 3; len < length; len += 4) {
-               ND_TCHECK_4(cp + len);
                ND_PRINT(" %s", GET_IPADDR_STRING(cp + len));
                if (ptr > len)
                        ND_PRINT(",");
        }
        return (0);
-
-trunc:
-       return (-1);
 }
 
 /*
index 27cafb3046445567aac7e822c742be5f722be717..6e9cbd143479e6a770b2ac3db4da913415ea63c8 100644 (file)
@@ -307,7 +307,6 @@ lisp_print(netdissect_options *ndo, const u_char *bp, u_int length)
 
                switch (eid_afi) {
                case IPv4_AFI:
-                       ND_TCHECK_4(packet_iterator + packet_offset);
                        ND_PRINT(" EID %s/%u,",
                                GET_IPADDR_STRING(packet_iterator + packet_offset),
                                mask_len);
index 21a1cbe9f6676d00f012cb377f26a69de91764f4..6c224b73aaf60eb3670672a6be1dbd4a0d314219 100644 (file)
@@ -808,7 +808,6 @@ of10_bsn_message_print(netdissect_options *ndo,
                /* pad */
                cp += 3;
                /* mask */
-               ND_TCHECK_4(cp);
                ND_PRINT(", mask %s", GET_IPADDR_STRING(cp));
                cp += 4;
                break;
@@ -1378,13 +1377,11 @@ of10_match_print(netdissect_options *ndo,
        ND_TCHECK_2(cp);
        cp += 2;
        /* nw_src */
-       ND_TCHECK_4(cp);
        nw_bits = (wildcards & OFPFW_NW_SRC_MASK) >> OFPFW_NW_SRC_SHIFT;
        if (nw_bits < 32)
                ND_PRINT("%smatch nw_src %s/%u", pfx, GET_IPADDR_STRING(cp), 32 - nw_bits);
        cp += 4;
        /* nw_dst */
-       ND_TCHECK_4(cp);
        nw_bits = (wildcards & OFPFW_NW_DST_MASK) >> OFPFW_NW_DST_SHIFT;
        if (nw_bits < 32)
                ND_PRINT("%smatch nw_dst %s/%u", pfx, GET_IPADDR_STRING(cp), 32 - nw_bits);
@@ -1514,7 +1511,6 @@ of10_actions_print(netdissect_options *ndo,
                case OFPAT_SET_NW_SRC:
                case OFPAT_SET_NW_DST:
                        /* nw_addr */
-                       ND_TCHECK_4(cp);
                        ND_PRINT(", nw_addr %s", GET_IPADDR_STRING(cp));
                        cp += 4;
                        break;
index a0474a39157b33e3c781c25ee008fd3c012c9aae..098763774ad53010454bbc6ae1e2b1dbdd254f94 100644 (file)
@@ -491,7 +491,6 @@ ospf_te_lsa_print(netdissect_options *ndo,
                 ND_PRINT("\n\t    TLV length %u < 4", tlv_length);
                 return -1;
             }
-            ND_TCHECK_4(tptr);
             ND_PRINT(", %s", GET_IPADDR_STRING(tptr));
             break;
 
@@ -698,7 +697,6 @@ ospf_print_lsa(netdissect_options *ndo,
                break;
 
        case LS_TYPE_NETWORK:
-               ND_TCHECK_4(lsap->lsa_un.un_nla.nla_mask);
                ND_PRINT("\n\t    Mask %s\n\t    Connected Routers:",
                    GET_IPADDR_STRING(lsap->lsa_un.un_nla.nla_mask));
                ap = lsap->lsa_un.un_nla.nla_router;
@@ -766,11 +764,9 @@ ospf_print_lsa(netdissect_options *ndo,
                        else
                                ND_PRINT(" %u", (ul & ASLA_MASK_METRIC));
 
-                       ND_TCHECK_4(almp->asla_forward);
                        if (GET_IPV4_TO_NETWORK_ORDER(almp->asla_forward) != 0) {
                                ND_PRINT(", forward %s", GET_IPADDR_STRING(almp->asla_forward));
                        }
-                       ND_TCHECK_4(almp->asla_tag);
                        if (GET_IPV4_TO_NETWORK_ORDER(almp->asla_tag) != 0) {
                                ND_PRINT(", tag %s", GET_IPADDR_STRING(almp->asla_tag));
                        }
@@ -782,7 +778,6 @@ ospf_print_lsa(netdissect_options *ndo,
                /* Multicast extensions as of 23 July 1991 */
                mcp = lsap->lsa_un.un_mcla;
                while ((const u_char *)mcp < ls_end) {
-                       ND_TCHECK_4(mcp->mcla_vid);
                        switch (GET_BE_U_4(mcp->mcla_vtype)) {
 
                        case MCLA_VERTEX_ROUTER:
@@ -999,12 +994,10 @@ ospf_decode_v2(netdissect_options *ndo,
                          GET_IPADDR_STRING(op->ospf_hello.hello_mask),
                          GET_U_1(op->ospf_hello.hello_priority));
 
-               ND_TCHECK_4(op->ospf_hello.hello_dr);
                if (GET_IPV4_TO_NETWORK_ORDER(op->ospf_hello.hello_dr) != 0)
                        ND_PRINT("\n\t  Designated Router %s",
                            GET_IPADDR_STRING(op->ospf_hello.hello_dr));
 
-               ND_TCHECK_4(op->ospf_hello.hello_bdr);
                if (GET_IPV4_TO_NETWORK_ORDER(op->ospf_hello.hello_bdr) != 0)
                        ND_PRINT(", Backup Designated Router %s",
                                  GET_IPADDR_STRING(op->ospf_hello.hello_bdr));
@@ -1134,10 +1127,8 @@ ospf_print(netdissect_options *ndo,
                dataend = bp + length;
        }
 
-       ND_TCHECK_4(op->ospf_routerid);
        ND_PRINT("\n\tRouter-ID %s", GET_IPADDR_STRING(op->ospf_routerid));
 
-       ND_TCHECK_4(op->ospf_areaid);
        if (GET_IPV4_TO_NETWORK_ORDER(op->ospf_areaid) != 0)
                ND_PRINT(", Area %s", GET_IPADDR_STRING(op->ospf_areaid));
        else
index 01a35d56a661a5cbe8ebb73ba0125987a312ff62..5e4f163dcebec03646c4695d491c7dd203dba4c6 100644 (file)
@@ -388,7 +388,6 @@ ospf6_print_lshdr(netdissect_options *ndo,
 {
        if ((const u_char *)(lshp + 1) > dataend)
                goto trunc;
-       ND_TCHECK_4(lshp->ls_router);
 
        ND_PRINT("\n\t  Advertising Router %s, seq 0x%08x, age %us, length %u",
                GET_IPADDR_STRING(lshp->ls_router),
@@ -617,7 +616,6 @@ ospf6_print_lsa(netdissect_options *ndo,
                        if (lsa_length < sizeof (uint32_t))
                                return (1);
                        lsa_length -= sizeof (uint32_t);
-                       ND_TCHECK_4(tptr);
                        ND_PRINT(" tag %s",
                               GET_IPADDR_STRING(tptr));
                        tptr += sizeof(uint32_t);
@@ -627,7 +625,6 @@ ospf6_print_lsa(netdissect_options *ndo,
                        if (lsa_length < sizeof (uint32_t))
                                return (1);
                        lsa_length -= sizeof (uint32_t);
-                       ND_TCHECK_4(tptr);
                        ND_PRINT(" RefLSID: %s",
                               GET_IPADDR_STRING(tptr));
                        tptr += sizeof(uint32_t);
@@ -980,7 +977,6 @@ ospf6_print(netdissect_options *ndo,
        }
        dataend = bp + datalen;
 
-       ND_TCHECK_4(op->ospf6_routerid);
        ND_PRINT("\n\tRouter-ID %s", GET_IPADDR_STRING(op->ospf6_routerid));
 
        if (GET_BE_U_4(op->ospf6_areaid) != 0)
index 1e63062e88d93177886b3d1c21be733c912749d6..186f84b5392b1ee56faa5717edf0a006021aa40a 100644 (file)
@@ -410,7 +410,6 @@ cisco_autorp_print(netdissect_options *ndo,
 
                if (len < 4)
                        goto trunc;
-               ND_TCHECK_4(bp);
                ND_PRINT(" RP %s", GET_IPADDR_STRING(bp));
                bp += 4;
                len -= 4;
@@ -913,7 +912,6 @@ pimv2_print(netdissect_options *ndo,
                ip = (const struct ip *)bp;
                switch (IP_V(ip)) {
                 case 0: /* Null header */
-                       ND_TCHECK_4(ip->ip_dst);
                        ND_PRINT("IP-Null-header %s > %s",
                                  GET_IPADDR_STRING(ip->ip_src),
                                  GET_IPADDR_STRING(ip->ip_dst));
index 759b06b118ec15bd85e0108f8e6c1455b270e2dc..fe0362473c5acc0b7f467002723c6907e1ebd0a8 100644 (file)
@@ -731,7 +731,6 @@ print_lcp_config_options(netdissect_options *ndo,
                                ND_PRINT(" (length bogus, should be = 7)");
                                return 0;
                        }
-                       ND_TCHECK_4(p + 3);
                        ND_PRINT(": IPv4 %s", GET_IPADDR_STRING(p + 3));
                        break;
                case MEDCLASS_MAC:
@@ -1038,7 +1037,6 @@ print_ipcp_config_options(netdissect_options *ndo,
                        ND_PRINT(" (length bogus, should be = 10)");
                        return len;
                }
-               ND_TCHECK_4(p + 6);
                ND_PRINT(": src %s, dst %s",
                       GET_IPADDR_STRING(p + 2),
                       GET_IPADDR_STRING(p + 6));
@@ -1124,7 +1122,6 @@ print_ipcp_config_options(netdissect_options *ndo,
                        ND_PRINT(" (length bogus, should be = 6)");
                        return 0;
                }
-               ND_TCHECK_4(p + 2);
                ND_PRINT(": %s", GET_IPADDR_STRING(p + 2));
                break;
        default:
index 181476fbf487e893daab1f8151ff9018ac018dae..cc181ad43ae5621ae070f1548ca3f5e65bbb5551 100644 (file)
@@ -1,2 +1 @@
-    1  11:22:39.003332 IP (tos 0x0, ttl 254, id 25615, offset 65480, flags [DF, rsvd], proto UDP (17), length 32768, options (LSRR [bad length 25] [bad ptr 15] 103.103.103.0, 0.172.0.116, 0.16.36.36, 16.0.36.2 14.9.36.4 [truncated-option]))
-    251.73.86.0 > 0.172.128.5:  [|ip]
+    1  11:22:39.003332 IP (tos 0x0, ttl 254, id 25615, offset 65480, flags [DF, rsvd], proto UDP (17), length 32768, options (LSRR [bad length 25] [bad ptr 15] 103.103.103.0, 0.172.0.116, 0.16.36.36, 16.0.36.2 14.9.36.4 [|ip]