Skip to content

Commit fc62f7d

Browse files
committed
net: fix handle unaligned memory access in net_context_bind()
This commit addresses an issue in net_context_bind() where unaligned memory access was not properly handled when checking for INADDR_ANY. The problem primarily affected MCUs like ARMv6 that don't support unaligned memory access. - Use UNALIGNED_GET() to safely access the sin_addr.s_addr field - Ensures correct behavior on architectures with alignment restrictions This fix improves compatibility and prevents potential crashes or unexpected behavior on affected platforms. Signed-off-by: Daekeun Kang <dkkang@huconn.com>
1 parent fba0a47 commit fc62f7d

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

subsys/net/ip/net_context.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ int net_context_bind(struct net_context *context, const struct sockaddr *addr,
865865

866866
ptr = &maddr->address.in_addr;
867867

868-
} else if (addr4->sin_addr.s_addr == INADDR_ANY) {
868+
} else if (UNALIGNED_GET(&addr4->sin_addr.s_addr) == INADDR_ANY) {
869869
if (iface == NULL) {
870870
iface = net_if_ipv4_select_src_iface(
871871
&net_sin(&context->remote)->sin_addr);

0 commit comments

Comments
 (0)