From: Francois-Xavier Le Bail Date: Tue, 30 Jan 2018 20:51:01 +0000 (+0100) Subject: RT6: Replace 'struct in6_addr' members type with a 'nd_ipv6' one X-Git-Tag: tcpdump-4.99-bp~1308 X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/7755951df76e2d6183005414f6908e5eb5eee335 RT6: Replace 'struct in6_addr' members type with a 'nd_ipv6' one 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 --- diff --git a/ip6.h b/ip6.h index 612f30cf..a821cd23 100644 --- 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 */ diff --git a/print-ip6.c b/print-ip6.c index b7ca0cf2..a8870ca2 100644 --- a/print-ip6.c +++ b/print-ip6.c @@ -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; diff --git a/print-rt6.c b/print-rt6.c index 2d3d3a8b..2c67c11d 100644 --- a/print-rt6.c +++ b/print-rt6.c @@ -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(") ");