]> The Tcpdump Group git mirrors - tcpdump/commitdiff
RT6: Replace 'struct in6_addr' members type with a 'nd_ipv6' one
authorFrancois-Xavier Le Bail <[email protected]>
Tue, 30 Jan 2018 20:51:01 +0000 (21:51 +0100)
committerFrancois-Xavier Le Bail <[email protected]>
Tue, 30 Jan 2018 21:17:36 +0000 (22:17 +0100)
In 'struct ip6_hdr', 'struct ip6_rthdr0' and 'struct ip6_srh'.
This avoid some 'undefined-behavior' warnings with clang and option
-fsanitize=undefined enabled.

print-rt6.c:66:3: runtime error: member access within misaligned address
0x61d00001eab6 for type 'const struct ip6_rthdr0', which requires 4 byte
alignment
0x61d00001eab6: note: pointer points here
 00 00 00 04 3a 02  00 01 00 00 00 00 22 00  00 00 00 00 02 10 00 02  00 00 00 00 00 04 80 00  d3 ab
             ^
SUMMARY: AddressSanitizer: undefined-behavior print-rt6.c:66:3 in

ip6.h
print-ip6.c
print-rt6.c

diff --git a/ip6.h b/ip6.h
index 612f30cf7c9ea76c045fd4cfb65e9a3d99476f25..a821cd2345e32cb8d15c2255a1c7fdc3da26a8d8 100644 (file)
--- a/ip6.h
+++ b/ip6.h
@@ -83,8 +83,8 @@ struct ip6_hdr {
                } ip6_un1;
                nd_uint8_t ip6_un2_vfc; /* 4 bits version, top 4 bits class */
        } ip6_ctlun;
-       struct in6_addr ip6_src;        /* source address */
-       struct in6_addr ip6_dst;        /* destination address */
+       nd_ipv6 ip6_src;        /* source address */
+       nd_ipv6 ip6_dst;        /* destination address */
 } ND_UNALIGNED;
 
 #define ip6_vfc                ip6_ctlun.ip6_un2_vfc
@@ -184,7 +184,7 @@ struct ip6_rthdr0 {
        nd_uint8_t  ip6r0_type;         /* always zero */
        nd_uint8_t  ip6r0_segleft;      /* segments left */
        nd_uint32_t ip6r0_reserved;     /* reserved field */
-       struct in6_addr ip6r0_addr[1];  /* up to 23 addresses */
+       nd_ipv6     ip6r0_addr[1];      /* up to 23 addresses */
 };
 
 /**
@@ -199,7 +199,7 @@ struct ip6_srh {
        nd_uint8_t      srh_last_ent;           /* Last Entry*/
        nd_uint8_t      srh_flags;              /* Flags */
        nd_uint16_t     srh_tag;                /* Tag */
-       struct in6_addr srh_segments[1];        /* SRH segments list*/
+       nd_ipv6         srh_segments[1];        /* SRH segments list*/
 };
 
 /* Fragment header */
index b7ca0cf2a1682815bb2e3bc7c3b9ee888f502813..a8870ca2cf8877294ce688ba47a74ef4a061359a 100644 (file)
@@ -53,7 +53,7 @@ ip6_finddst(netdissect_options *ndo, struct in6_addr *dst,
        const void *dst_addr;
        const struct ip6_rthdr *dp;
        const struct ip6_rthdr0 *dp0;
-       const struct in6_addr *addr;
+       const u_char *p;
        int i, len;
 
        cp = (const u_char *)ip6;
@@ -107,13 +107,11 @@ ip6_finddst(netdissect_options *ndo, struct in6_addr *dst,
                                if (len % 2 == 1)
                                        goto trunc;
                                len >>= 1;
-                               addr = &dp0->ip6r0_addr[0];
+                               p = (const u_char *) dp0->ip6r0_addr;
                                for (i = 0; i < len; i++) {
-                                       if ((const u_char *)(addr + 1) > ndo->ndo_snapend)
-                                               goto trunc;
-
-                                       dst_addr = (const void *)addr;
-                                       addr++;
+                                       ND_TCHECK_16(p);
+                                       dst_addr = (const void *)p;
+                                       p += 16;
                                }
                                break;
 
index 2d3d3a8bf591bc8987182c552593478920b7bfaa..2c67c11dbacbe5b39d77ea66a62b6063f13915a9 100644 (file)
@@ -41,15 +41,11 @@ rt6_print(netdissect_options *ndo, const u_char *bp, const u_char *bp2 _U_)
        const struct ip6_rthdr *dp;
        const struct ip6_rthdr0 *dp0;
        const struct ip6_srh *srh;
-       const u_char *ep;
        u_int i, len, type;
-       const struct in6_addr *addr;
+       const u_char *p;
 
        dp = (const struct ip6_rthdr *)bp;
 
-       /* 'ep' points to the end of available data. */
-       ep = ndo->ndo_snapend;
-
        ND_TCHECK_1(dp->ip6r_segleft);
 
        len = EXTRACT_U_1(dp->ip6r_len);
@@ -72,13 +68,11 @@ rt6_print(netdissect_options *ndo, const u_char *bp, const u_char *bp2 _U_)
                if (len % 2 == 1)
                        goto trunc;
                len >>= 1;
-               addr = &dp0->ip6r0_addr[0];
+               p = (const u_char *) dp0->ip6r0_addr;
                for (i = 0; i < len; i++) {
-                       if ((const u_char *)(addr + 1) > ep)
-                               goto trunc;
-
-                       ND_PRINT(", [%u]%s", i, ip6addr_string(ndo, addr));
-                       addr++;
+                       ND_TCHECK_16(p);
+                       ND_PRINT(", [%u]%s", i, ip6addr_string(ndo, p));
+                       p += 16;
                }
                /*(*/
                ND_PRINT(") ");
@@ -101,13 +95,11 @@ rt6_print(netdissect_options *ndo, const u_char *bp, const u_char *bp2 _U_)
                if (len % 2 == 1)
                        goto trunc;
                len >>= 1;
-               addr = &srh->srh_segments[0];
+               p  = (const u_char *) srh->srh_segments;
                for (i = 0; i < len; i++) {
-                       if ((const u_char *)(addr + 1) > ep)
-                               goto trunc;
-
-                       ND_PRINT(", [%u]%s", i, ip6addr_string(ndo, addr));
-                       addr++;
+                       ND_TCHECK_16(p);
+                       ND_PRINT(", [%u]%s", i, ip6addr_string(ndo, p));
+                       p += 16;
                }
                /*(*/
                ND_PRINT(") ");