Skip to content

Commit 998e839

Browse files
MirkoCovizzicarlescufi
authored andcommitted
net: sockets: prevent null pointer dereference
According to the POSIX specification, null pointer is a valid value for the `address` argument of the `accept` function. This commit adds a check to prevent a null pointer dereference inside `z_impl_zsock_accept`. Signed-off-by: Mirko Covizzi <[email protected]>
1 parent 325bc95 commit 998e839

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

subsys/net/lib/sockets/sockets.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,9 @@ int z_impl_zsock_accept(int sock, struct sockaddr *addr, socklen_t *addrlen)
684684

685685
new_sock = VTABLE_CALL(accept, sock, addr, addrlen);
686686

687-
(void)sock_obj_core_alloc_find(sock, new_sock, addr->sa_family, SOCK_STREAM);
687+
if (addr) {
688+
(void)sock_obj_core_alloc_find(sock, new_sock, addr->sa_family, SOCK_STREAM);
689+
}
688690

689691
return new_sock;
690692
}

0 commit comments

Comments
 (0)