net: sockets: tls: Check accepted context is not NULL

When closing a listening socket the functions waiting on the
FIFO will be unblocked this will result in receiving a NULL child
context. If that is the case return an error instead of carrying on.
Return the same error code (EINVAL) that is returned on Linux when
calling shutdown on a blocked accept call.

Signed-off-by: Léonard Bise <leonard.bise@gmail.com>
This commit is contained in:
Léonard Bise 2020-06-10 09:15:46 +02:00 committed by Jukka Rissanen
commit 5cedb73555

View file

@ -1277,6 +1277,14 @@ int ztls_accept_ctx(struct net_context *parent, struct sockaddr *addr,
} }
child = k_fifo_get(&parent->accept_q, K_FOREVER); child = k_fifo_get(&parent->accept_q, K_FOREVER);
if (child == NULL) {
z_free_fd(fd);
/* Return EINVAL which is the same error code used under Linux
* when calling shutdown on a blocked accept call
*/
errno = EINVAL;
return -1;
}
if (addr != NULL && addrlen != NULL) { if (addr != NULL && addrlen != NULL) {
int len = MIN(*addrlen, sizeof(child->remote)); int len = MIN(*addrlen, sizeof(child->remote));