Skip to content

Commit b24c520

Browse files
hulryungcarlescufi
authored andcommitted
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 5b41ea7 commit b24c520

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
@@ -876,7 +876,7 @@ int net_context_bind(struct net_context *context, const struct sockaddr *addr,
876876

877877
ptr = &maddr->address.in_addr;
878878

879-
} else if (addr4->sin_addr.s_addr == INADDR_ANY) {
879+
} else if (UNALIGNED_GET(&addr4->sin_addr.s_addr) == INADDR_ANY) {
880880
if (iface == NULL) {
881881
iface = net_if_ipv4_select_src_iface(
882882
&net_sin(&context->remote)->sin_addr);

0 commit comments

Comments
 (0)