]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Fix some narrowing warnings on LP64/LLP64 platforms.
authorGuy Harris <[email protected]>
Thu, 18 Apr 2019 17:13:49 +0000 (10:13 -0700)
committerGuy Harris <[email protected]>
Thu, 18 Apr 2019 17:13:49 +0000 (10:13 -0700)
Add a ND_BYTES_AVAILABLE_AFTER() macro to find the number of bytes
available in the captured data, starting at the byte pointed to by the
argument.  It returns a u_int rather than a ptrdiff_t, so it'll be
32 bits on LP64 and LLP64 platforms as well as on ILP32 platforms.  Use
that macro.

Make size-of-buffer arguments size_t.

Cast some size_t and ptrdiff_t values to u_int or int.

19 files changed:
netdissect.h
print-ascii.c
print-bgp.c
print-chdlc.c
print-fr.c
print-geneve.c
print-gre.c
print-lisp.c
print-lwres.c
print-mobility.c
print-nsh.c
print-olsr.c
print-openflow-1.0.c
print-otv.c
print-ppp.c
print-rip.c
print-telnet.c
print-vxlan-gpe.c
print-vxlan.c

index 822dd9c7be9929645ccaaf1921793be522d146de..3feeb4667db4c0bd939ff6ce2bc29f55fd1b9454 100644 (file)
@@ -356,6 +356,12 @@ extern void nd_pop_all_buffers(netdissect_options *);
 /* Bail out if "*(p)" was not captured */
 #define ND_TCHECK_SIZE(p) ND_TCHECK_LEN(p, sizeof(*(p)))
 
+/*
+ * Number of bytes remaining in the captured data, starting at the
+ * byte pointed to by the argument.
+ */
+#define ND_BYTES_AVAILABLE_AFTER(p) ((u_int)(ndo->ndo_snapend - (p)))
+
 #define ND_PRINT(...) (ndo->ndo_printf)(ndo, __VA_ARGS__)
 #define ND_DEFAULTPRINT(ap, length) (*ndo->ndo_default_print)(ndo, ap, length)
 
@@ -731,8 +737,8 @@ extern int mask62plen(const u_char *);
 extern const char *dnname_string(netdissect_options *, u_short);
 extern const char *dnnum_string(netdissect_options *, u_short);
 
-extern int decode_prefix4(netdissect_options *, const u_char *, u_int, char *, u_int);
-extern int decode_prefix6(netdissect_options *, const u_char *, u_int, char *, u_int);
+extern int decode_prefix4(netdissect_options *, const u_char *, u_int, char *, size_t);
+extern int decode_prefix6(netdissect_options *, const u_char *, u_int, char *, size_t);
 
 extern void esp_print_decodesecret(netdissect_options *);
 extern int esp_print_decrypt_buffer_by_ikev2(netdissect_options *, int,
index 8460f84baf2ca8bd0f98130b06342ed8096e4285..63f15f0f14215fe6708188a4b479494597dc7b88 100644 (file)
@@ -65,7 +65,7 @@ ascii_print(netdissect_options *ndo,
        u_char s;
 
        ndo->ndo_protocol = "ascii";
-       caplength = (ndo->ndo_snapend > cp) ? ndo->ndo_snapend - cp : 0;
+       caplength = (ndo->ndo_snapend > cp) ? ND_BYTES_AVAILABLE_AFTER(cp) : 0;
        if (length > caplength)
                length = caplength;
        ND_PRINT("\n");
@@ -106,7 +106,7 @@ hex_and_ascii_print_with_offset(netdissect_options *ndo, const char *ident,
        char hexstuff[HEXDUMP_SHORTS_PER_LINE*HEXDUMP_HEXSTUFF_PER_SHORT+1], *hsp;
        char asciistuff[ASCII_LINELENGTH+1], *asp;
 
-       caplength = (ndo->ndo_snapend > cp) ? ndo->ndo_snapend - cp : 0;
+       caplength = (ndo->ndo_snapend > cp) ? ND_BYTES_AVAILABLE_AFTER(cp) : 0;
        if (length > caplength)
                length = caplength;
        nshorts = length / sizeof(u_short);
@@ -169,7 +169,7 @@ hex_print_with_offset(netdissect_options *ndo,
        u_int i, s;
        u_int nshorts;
 
-       caplength = (ndo->ndo_snapend > cp) ? ndo->ndo_snapend - cp : 0;
+       caplength = (ndo->ndo_snapend > cp) ? ND_BYTES_AVAILABLE_AFTER(cp) : 0;
        if (length > caplength)
                length = caplength;
        nshorts = length / sizeof(u_short);
index a82dc8fe7b5e57fa93a734d27aa4760645b50e9d..dbbf7721098731d7b2ca7e565da3886fd5f3e737 100644 (file)
@@ -535,7 +535,7 @@ as_printf(netdissect_options *ndo,
 
 int
 decode_prefix4(netdissect_options *ndo,
-               const u_char *pptr, u_int itemlen, char *buf, u_int buflen)
+               const u_char *pptr, u_int itemlen, char *buf, size_t buflen)
 {
     struct in_addr addr;
     u_int plen, plenbytes;
@@ -567,7 +567,8 @@ badtlv:
 
 static int
 decode_labeled_prefix4(netdissect_options *ndo,
-                       const u_char *pptr, u_int itemlen, char *buf, u_int buflen)
+                       const u_char *pptr, u_int itemlen, char *buf,
+                       size_t buflen)
 {
     struct in_addr addr;
     u_int plen, plenbytes;
@@ -672,7 +673,7 @@ trunc:
  */
 static u_int
 bgp_vpn_sg_print(netdissect_options *ndo,
-                 const u_char *pptr, char *buf, u_int buflen)
+                 const u_char *pptr, char *buf, size_t buflen)
 {
     uint8_t addr_length;
     u_int total_length, offset;
@@ -687,7 +688,7 @@ bgp_vpn_sg_print(netdissect_options *ndo,
     /* Source address */
     ND_TCHECK_LEN(pptr, (addr_length >> 3));
     total_length += (addr_length >> 3) + 1;
-    offset = strlen(buf);
+    offset = (u_int)strlen(buf);
     if (addr_length) {
         nd_snprintf(buf + offset, buflen - offset, ", Source %s",
              bgp_vpn_ip_print(ndo, pptr, addr_length));
@@ -702,7 +703,7 @@ bgp_vpn_sg_print(netdissect_options *ndo,
     /* Group address */
     ND_TCHECK_LEN(pptr, (addr_length >> 3));
     total_length += (addr_length >> 3) + 1;
-    offset = strlen(buf);
+    offset = (u_int)strlen(buf);
     if (addr_length) {
         nd_snprintf(buf + offset, buflen - offset, ", Group %s",
              bgp_vpn_ip_print(ndo, pptr, addr_length));
@@ -901,7 +902,7 @@ trunc:
 
 static int
 decode_labeled_vpn_prefix4(netdissect_options *ndo,
-                           const u_char *pptr, char *buf, u_int buflen)
+                           const u_char *pptr, char *buf, size_t buflen)
 {
     struct in_addr addr;
     u_int plen;
@@ -952,7 +953,7 @@ trunc:
 
 static int
 decode_mdt_vpn_nlri(netdissect_options *ndo,
-                    const u_char *pptr, char *buf, u_int buflen)
+                    const u_char *pptr, char *buf, size_t buflen)
 {
     const u_char *rd;
     const u_char *vpn_ip;
@@ -1027,7 +1028,7 @@ decode_multicast_vpn(netdissect_options *ndo,
     switch(route_type) {
     case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI:
         ND_TCHECK_LEN(pptr, BGP_VPN_RD_LEN);
-        offset = strlen(buf);
+        offset = (u_int)strlen(buf);
         nd_snprintf(buf + offset, buflen - offset, ", RD: %s, Originator %s",
                     bgp_vpn_rd_print(ndo, pptr),
                     bgp_vpn_ip_print(ndo, pptr + BGP_VPN_RD_LEN,
@@ -1035,7 +1036,7 @@ decode_multicast_vpn(netdissect_options *ndo,
         break;
     case BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI:
         ND_TCHECK_LEN(pptr, BGP_VPN_RD_LEN + 4);
-        offset = strlen(buf);
+        offset = (u_int)strlen(buf);
         nd_snprintf(buf + offset, buflen - offset, ", RD: %s, Source-AS %s",
         bgp_vpn_rd_print(ndo, pptr),
         as_printf(ndo, astostr, sizeof(astostr),
@@ -1044,7 +1045,7 @@ decode_multicast_vpn(netdissect_options *ndo,
 
     case BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI:
         ND_TCHECK_LEN(pptr, BGP_VPN_RD_LEN);
-        offset = strlen(buf);
+        offset = (u_int)strlen(buf);
         nd_snprintf(buf + offset, buflen - offset, ", RD: %s",
                     bgp_vpn_rd_print(ndo, pptr));
         pptr += BGP_VPN_RD_LEN;
@@ -1053,14 +1054,14 @@ decode_multicast_vpn(netdissect_options *ndo,
         addr_length =  route_length - sg_length;
 
         ND_TCHECK_LEN(pptr, addr_length);
-        offset = strlen(buf);
+        offset = (u_int)strlen(buf);
         nd_snprintf(buf + offset, buflen - offset, ", Originator %s",
                     bgp_vpn_ip_print(ndo, pptr, addr_length << 3));
         break;
 
     case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE:
         ND_TCHECK_LEN(pptr, BGP_VPN_RD_LEN);
-        offset = strlen(buf);
+        offset = (u_int)strlen(buf);
         nd_snprintf(buf + offset, buflen - offset, ", RD: %s",
                     bgp_vpn_rd_print(ndo, pptr));
         pptr += BGP_VPN_RD_LEN;
@@ -1071,7 +1072,7 @@ decode_multicast_vpn(netdissect_options *ndo,
     case BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN: /* fall through */
     case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN:
         ND_TCHECK_LEN(pptr, BGP_VPN_RD_LEN + 4);
-        offset = strlen(buf);
+        offset = (u_int)strlen(buf);
         nd_snprintf(buf + offset, buflen - offset, ", RD: %s, Source-AS %s",
                     bgp_vpn_rd_print(ndo, pptr),
                     as_printf(ndo, astostr, sizeof(astostr),
@@ -1117,7 +1118,7 @@ trunc:
 
 static int
 decode_labeled_vpn_l2(netdissect_options *ndo,
-                      const u_char *pptr, char *buf, u_int buflen)
+                      const u_char *pptr, char *buf, size_t buflen)
 {
     u_int plen, tlen, tlv_type, tlv_len, ttlv_len;
     int stringlen;
@@ -1230,7 +1231,7 @@ trunc:
 
 int
 decode_prefix6(netdissect_options *ndo,
-               const u_char *pd, u_int itemlen, char *buf, u_int buflen)
+               const u_char *pd, u_int itemlen, char *buf, size_t buflen)
 {
     struct in6_addr addr;
     u_int plen, plenbytes;
@@ -1263,7 +1264,7 @@ badtlv:
 
 static int
 decode_labeled_prefix6(netdissect_options *ndo,
-               const u_char *pptr, u_int itemlen, char *buf, u_int buflen)
+               const u_char *pptr, u_int itemlen, char *buf, size_t buflen)
 {
     struct in6_addr addr;
     u_int plen, plenbytes;
@@ -1308,7 +1309,7 @@ badtlv:
 
 static int
 decode_labeled_vpn_prefix6(netdissect_options *ndo,
-                           const u_char *pptr, char *buf, u_int buflen)
+                           const u_char *pptr, char *buf, size_t buflen)
 {
     struct in6_addr addr;
     u_int plen;
@@ -1347,7 +1348,7 @@ trunc:
 
 static int
 decode_clnp_prefix(netdissect_options *ndo,
-                   const u_char *pptr, char *buf, u_int buflen)
+                   const u_char *pptr, char *buf, size_t buflen)
 {
     uint8_t addr[19];
     u_int plen;
@@ -1377,7 +1378,7 @@ trunc:
 
 static int
 decode_labeled_vpn_clnp_prefix(netdissect_options *ndo,
-                               const u_char *pptr, char *buf, u_int buflen)
+                               const u_char *pptr, char *buf, size_t buflen)
 {
     uint8_t addr[19];
     u_int plen;
index 6659f9dfbad65986be360be0a2f83455d1082314..bc431774537fcb24f347d6e77d3c5514b484182c 100644 (file)
@@ -114,7 +114,7 @@ chdlc_print(netdissect_options *ndo, const u_char *p, u_int length)
 
 trunc:
        nd_print_trunc(ndo);
-       return ndo->ndo_snapend - bp;
+       return (ND_BYTES_AVAILABLE_AFTER(bp));
 }
 
 /*
index 5a7365477e569d2779aa09f8b0c9be9d9c7a237c..9a9273ec02dac2922772c897e6f973979a74f857 100644 (file)
@@ -276,7 +276,7 @@ fr_print(netdissect_options *ndo,
                         if (ethertype_print(ndo, extracted_ethertype,
                                             p+addr_len+ETHERTYPE_LEN,
                                             length-addr_len-ETHERTYPE_LEN,
-                                            ndo->ndo_snapend-p-addr_len-ETHERTYPE_LEN,
+                                            ND_BYTES_AVAILABLE_AFTER(p)-addr_len-ETHERTYPE_LEN,
                                             NULL, NULL) == 0)
                                 /* ether_type not known, probably it wasn't one */
                                 ND_PRINT("UI %02x! ", GET_U_1(p + addr_len));
@@ -333,7 +333,7 @@ fr_print(netdissect_options *ndo,
                break;
 
        case NLPID_SNAP:
-               if (snap_print(ndo, p, length, ndo->ndo_snapend - p, NULL, NULL, 0) == 0) {
+               if (snap_print(ndo, p, length, ND_BYTES_AVAILABLE_AFTER(p), NULL, NULL, 0) == 0) {
                        /* ether_type not known, print raw packet */
                         if (!ndo->ndo_eflag)
                             fr_hdr_print(ndo, length + hdr_len, hdr_len,
index fa6791101ef0b95089a3c08007015c532346ecb4..06c1e284d3dba97b50cbba0e0ccfcc5335277e54 100644 (file)
@@ -224,9 +224,9 @@ geneve_print(netdissect_options *ndo, const u_char *bp, u_int len)
     else
         ND_PRINT("\n\t");
 
-    if (ethertype_print(ndo, prot, bp, len, ndo->ndo_snapend - bp, NULL, NULL) == 0) {
+    if (ethertype_print(ndo, prot, bp, len, ND_BYTES_AVAILABLE_AFTER(bp), NULL, NULL) == 0) {
         if (prot == ETHERTYPE_TEB)
-            ether_print(ndo, bp, len, ndo->ndo_snapend - bp, NULL, NULL);
+            ether_print(ndo, bp, len, ND_BYTES_AVAILABLE_AFTER(bp), NULL, NULL);
         else
             ND_PRINT("geneve-proto-0x%x", prot);
     }
index 773c030c1776cc454b88e9257eca32f71ada8f04..09b2be113306267228a6fb5a5861c2e4b7714ec7 100644 (file)
@@ -224,7 +224,7 @@ gre_print_0(netdissect_options *ndo, const u_char *bp, u_int length)
                isoclns_print(ndo, bp, len);
                break;
        case ETHERTYPE_TEB:
-               ether_print(ndo, bp, len, ndo->ndo_snapend - bp, NULL, NULL);
+               ether_print(ndo, bp, len, ND_BYTES_AVAILABLE_AFTER(bp), NULL, NULL);
                break;
        default:
                ND_PRINT("gre-proto-0x%x", prot);
index a7d088d4b5d31c33e36483e848b1112b35e4f6b9..5c6825ae6d974bdcde9d4ec16f519cca3b7bdb87 100644 (file)
@@ -381,7 +381,7 @@ lisp_print(netdissect_options *ndo, const u_char *bp, u_int length)
                /* Check if packet isn't over yet */
                if (packet_iterator + packet_offset < ndo->ndo_snapend) {
                        hex_print_with_offset(ndo, "\n    Data: ", packet_iterator + packet_offset,
-                               (ndo->ndo_snapend - (packet_iterator + packet_offset)), 0);
+                               ND_BYTES_AVAILABLE_AFTER(packet_iterator + packet_offset), 0);
                }
        }
        return;
index a8e83bf595eef003a45c83366316dccc781d8350..0d2cbb4b9a88af3f67400deed6519851079e6ac6 100644 (file)
@@ -210,7 +210,7 @@ lwres_printname(netdissect_options *ndo,
        }
        p++;    /* skip terminating \0 */
 
-       return p - p0;
+       return (int)(p - p0);
 
   trunc:
        return -1;
@@ -254,7 +254,7 @@ lwres_printbinlen(netdissect_options *ndo,
                ND_PRINT("%02x", GET_U_1(p));
                p++;
        }
-       return p - p0;
+       return (int)(p - p0);
 
   trunc:
        return -1;
index 4dbfb6ff3b8ec5f7b56b97dcf4bfef38cfe78011..8272664bdd86f2bd3b3f21818a2f16eb86d72012 100644 (file)
@@ -227,7 +227,7 @@ mobility_print(netdissect_options *ndo,
                 * returned length, however, as it breaks out of the
                 * header-processing loop.
                 */
-               mhlen = ep - bp;
+               mhlen = (unsigned)(ep - bp);
                goto trunc;
        }
        mhlen = (GET_U_1(mh->ip6m_len) + 1) << 3;
index d752b247589146afba070985c7c73aa4d29282be..17d6256925bd1e4b6a36071bc8de354eb733ab7c 100644 (file)
@@ -170,7 +170,7 @@ nsh_print(netdissect_options *ndo, const u_char *bp, u_int len)
         ip6_print(ndo, bp, next_len);
         break;
     case 0x3:
-        ether_print(ndo, bp, next_len, ndo->ndo_snapend - bp, NULL, NULL);
+        ether_print(ndo, bp, next_len, ND_BYTES_AVAILABLE_AFTER(bp), NULL, NULL);
         break;
     default:
         ND_PRINT("ERROR: unknown-next-protocol");
index 8e3adbbb782b3202d691f30430b4baa1f5f19017..a8ab62f2d97e09d4ecdaac6f199fb2981f463dff 100644 (file)
@@ -519,10 +519,10 @@ olsr_print(netdissect_options *ndo,
 
         case OLSR_MID_MSG:
         {
-            size_t addr_size = sizeof(nd_ipv4);
+            u_int addr_size = (u_int)sizeof(nd_ipv4);
 
             if (is_ipv6)
-                addr_size = sizeof(nd_ipv6);
+                addr_size = (u_int)sizeof(nd_ipv6);
 
             while (msg_tlen >= addr_size) {
                 ND_TCHECK_LEN(msg_data, addr_size);
index d1cafc5dae8e3a8a7400b93c395c7e7c0375cb13..048031aa9b9e1221d22b9291c3428cd34c1358dc 100644 (file)
@@ -1128,7 +1128,7 @@ of10_packet_data_print(netdissect_options *ndo,
        ND_TCHECK_LEN(cp, len);
        ndo->ndo_vflag -= 3;
        ND_PRINT(", frame decoding below\n");
-       ether_print(ndo, cp, len, ndo->ndo_snapend - cp, NULL, NULL);
+       ether_print(ndo, cp, len, ND_BYTES_AVAILABLE_AFTER(cp), NULL, NULL);
        ndo->ndo_vflag += 3;
        return cp + len;
 
index d7f0d86bed750415f9458b08cbfa0ce9f87fb46b..dbcef9f676c28a8e003eeb2c5097b096f4d9ce33 100644 (file)
@@ -67,7 +67,7 @@ otv_print(netdissect_options *ndo, const u_char *bp, u_int len)
     ND_TCHECK_1(bp);
     bp += 1;
 
-    ether_print(ndo, bp, len - OTV_HDR_LEN, ndo->ndo_snapend - bp, NULL, NULL);
+    ether_print(ndo, bp, len - OTV_HDR_LEN, ND_BYTES_AVAILABLE_AFTER(bp), NULL, NULL);
     return;
 
 trunc:
index 1f82e7da97682e83433422ca46bfd261bad505fa..a1b3214f30cdfcd8c7dd0bd7f69798c5cbcceddb 100644 (file)
@@ -906,7 +906,7 @@ handle_chap(netdissect_options *ndo,
                        ND_PRINT("%02x", GET_U_1(p));
                        p++;
                }
-               name_size = len - (p - p0);
+               name_size = len - (u_int)(p - p0);
                ND_PRINT(", Name ");
                for (i = 0; i < name_size; i++) {
                        ND_TCHECK_1(p);
@@ -916,7 +916,7 @@ handle_chap(netdissect_options *ndo,
                break;
        case CHAP_SUCC:
        case CHAP_FAIL:
-               msg_size = len - (p - p0);
+               msg_size = len - (u_int)(p - p0);
                ND_PRINT(", Msg ");
                for (i = 0; i< msg_size; i++) {
                        ND_TCHECK_1(p);
@@ -1443,7 +1443,7 @@ ppp_hdlc(netdissect_options *ndo,
         */
        se = ndo->ndo_snapend;
        ndo->ndo_snapend = t;
-       length = t - b;
+       length = ND_BYTES_AVAILABLE_AFTER(b);
 
         /* now lets guess about the payload codepoint format */
         if (length < 1)
index c8d17c3ec98add000333a58379dccea4e84dd771..c749c36760b05a9bc32ffc7f181f4496205957b7 100644 (file)
@@ -303,7 +303,7 @@ rip_print(netdissect_options *ndo,
                nd_print_trunc(ndo);
                return;
        }
-       len = ndo->ndo_snapend - dat;
+       len = ND_BYTES_AVAILABLE_AFTER(dat);
        if (len > length)
                len = length;
        if (len < sizeof(*rp)) {
index e6223d9bb7d90e2db468915d4e8c4114d2a19f5f..f2ff1389f17d4b0a6e326cf16050655502caa481 100644 (file)
@@ -497,7 +497,7 @@ telnet_parse(netdissect_options *ndo, const u_char *sp, u_int length, int print)
        }
 
 done:
-       return sp - osp;
+       return (int)(sp - osp);
 
 trunc:
        nd_print_trunc(ndo);
@@ -532,7 +532,7 @@ telnet_print(netdissect_options *ndo, const u_char *sp, u_int length)
                if (ndo->ndo_Xflag && 2 < ndo->ndo_vflag) {
                        if (first)
                                ND_PRINT("\nTelnet:");
-                       hex_print_with_offset(ndo, "\n", sp, l, sp - osp);
+                       hex_print_with_offset(ndo, "\n", sp, l, (u_int)(sp - osp));
                        if (l > 8)
                                ND_PRINT("\n\t\t\t\t");
                        else
index 1364534ed20317d17a6e4906ef5ebde71490f0ab..d7a80f25dfdb83e64659320e41b35d6efae8fa8e 100644 (file)
@@ -92,7 +92,7 @@ vxlan_gpe_print(netdissect_options *ndo, const u_char *bp, u_int len)
         ip6_print(ndo, bp, len - VXLAN_GPE_HDR_LEN);
         break;
     case 0x3:
-        ether_print(ndo, bp, len - VXLAN_GPE_HDR_LEN, ndo->ndo_snapend - bp, NULL, NULL);
+        ether_print(ndo, bp, len - VXLAN_GPE_HDR_LEN, ND_BYTES_AVAILABLE_AFTER(bp), NULL, NULL);
         break;
     case 0x4:
         nsh_print(ndo, bp, len - VXLAN_GPE_HDR_LEN);
index a27b1d7116b62a3cf3f076c783e80703870b47ee..d2b896b094503dcf9f215c75fd65965f83e55753 100644 (file)
@@ -65,7 +65,7 @@ vxlan_print(netdissect_options *ndo, const u_char *bp, u_int len)
     ND_PRINT("flags [%s] (0x%02x), ", flags & 0x08 ? "I" : ".", flags);
     ND_PRINT("vni %u\n", vni);
 
-    ether_print(ndo, bp, len - VXLAN_HDR_LEN, ndo->ndo_snapend - bp, NULL, NULL);
+    ether_print(ndo, bp, len - VXLAN_HDR_LEN, ND_BYTES_AVAILABLE_AFTER(bp), NULL, NULL);
 
     return;