]> The Tcpdump Group git mirrors - tcpdump/commitdiff
HSRP: Replace a 'struct in_addr' member type with a 'nd_ipv4' one
authorFrancois-Xavier Le Bail <[email protected]>
Tue, 30 Jan 2018 14:06:07 +0000 (15:06 +0100)
committerFrancois-Xavier Le Bail <[email protected]>
Tue, 30 Jan 2018 15:38:37 +0000 (16:38 +0100)
In 'struct hsrp'.
This avoid some 'undefined-behavior' warnings with clang and option
-fsanitize=undefined enabled.

Moreover:
Remove unneeded '&' when getting a pointer to a nd_ipv4 type.

The warnings were like:
print-hsrp.c:102:2: runtime error: member access within misaligned address
0x61d00001eaaa for type 'const struct hsrp', which requires 4 byte alignment
0x61d00001eaaa: note: pointer points here
 00 1c  2d 8d 00 00 10 03 0a 64  01 00 63 69 73 63 6f 00  00 00 c0 a8 00 01 be be  be be be be be be
              ^
SUMMARY: AddressSanitizer: undefined-behavior print-hsrp.c:102:2 in

print-hsrp.c

index ba89a0e0bdaec61fbbefbf6515f97cc1d83e60c4..42ce76030b5dc6b6a849b758a76e37c259d0baa5 100644 (file)
@@ -90,7 +90,7 @@ struct hsrp {
        nd_uint8_t      hsrp_group;
        nd_uint8_t      hsrp_reserved;
        nd_byte         hsrp_authdata[HSRP_AUTH_SIZE];
-       struct in_addr  hsrp_virtaddr;
+       nd_ipv4         hsrp_virtaddr;
 };
 
 void
@@ -116,8 +116,8 @@ hsrp_print(netdissect_options *ndo, const uint8_t *bp, u_int len)
        if (EXTRACT_U_1(hp->hsrp_reserved) != 0) {
                ND_PRINT("[reserved=%u!] ", EXTRACT_U_1(hp->hsrp_reserved));
        }
-       ND_TCHECK_4(&hp->hsrp_virtaddr);
-       ND_PRINT("addr=%s", ipaddr_string(ndo, &hp->hsrp_virtaddr));
+       ND_TCHECK_4(hp->hsrp_virtaddr);
+       ND_PRINT("addr=%s", ipaddr_string(ndo, hp->hsrp_virtaddr));
        if (ndo->ndo_vflag) {
                ND_PRINT(" hellotime=");
                unsigned_relts_print(ndo, EXTRACT_U_1(hp->hsrp_hellotime));