Skip to content

Commit 6937dab

Browse files
hulryunghenrikbrixandersen
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 <[email protected]> (cherry picked from commit b24c520)
1 parent 25d2970 commit 6937dab

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

856856
ptr = &maddr->address.in_addr;
857857

858-
} else if (addr4->sin_addr.s_addr == INADDR_ANY) {
858+
} else if (UNALIGNED_GET(&addr4->sin_addr.s_addr) == INADDR_ANY) {
859859
if (iface == NULL) {
860860
iface = net_if_ipv4_select_src_iface(
861861
&net_sin(&context->remote)->sin_addr);

0 commit comments

Comments
 (0)