Skip to content

Commit

Permalink
[nrf fromtree] net: sockets: prevent null pointer dereference
Browse files Browse the repository at this point in the history
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]>
(cherry picked from commit f3b2c04)
  • Loading branch information
MirkoCovizzi committed Jan 16, 2024
1 parent f6e704c commit 1c09551
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion subsys/net/lib/sockets/sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,9 @@ int z_impl_zsock_accept(int sock, struct sockaddr *addr, socklen_t *addrlen)

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

(void)sock_obj_core_alloc_find(sock, new_sock, addr->sa_family, SOCK_STREAM);
if (addr) {
(void)sock_obj_core_alloc_find(sock, new_sock, addr->sa_family, SOCK_STREAM);
}

return new_sock;
}
Expand Down

0 comments on commit 1c09551

Please sign in to comment.