Skip to content

Commit a1d916e

Browse files
aescolardanieldegrasse
authored andcommitted
net: dhcpv6: Avoid directly accessing address of unaligned struct
Use UNALIGNED_MEMBER_ADDR when getting the address of possibly unaligned structures members instead of attempting to directly get the address as an offset. Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
1 parent 1deb2e3 commit a1d916e

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

subsys/net/lib/dhcpv6/dhcpv6.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2250,8 +2250,10 @@ static void dhcpv6_generate_client_duid(struct net_if *iface)
22502250

22512251
memset(clientid, 0, sizeof(*clientid));
22522252

2253-
UNALIGNED_PUT(htons(DHCPV6_DUID_TYPE_LL), &clientid->duid.type);
2254-
UNALIGNED_PUT(htons(DHCPV6_HARDWARE_ETHERNET_TYPE), &duid_ll->hw_type);
2253+
UNALIGNED_PUT(htons(DHCPV6_DUID_TYPE_LL),
2254+
UNALIGNED_MEMBER_ADDR(clientid, duid.type));
2255+
UNALIGNED_PUT(htons(DHCPV6_HARDWARE_ETHERNET_TYPE),
2256+
UNALIGNED_MEMBER_ADDR(duid_ll, hw_type));
22552257
memcpy(duid_ll->ll_addr, lladdr->addr, lladdr->len);
22562258

22572259
clientid->length = DHCPV6_DUID_LL_HEADER_SIZE + lladdr->len;

0 commit comments

Comments
 (0)