From 81b92fcbb365e9f65d4e20176dfbdfe670abc6a3 Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Fri, 4 Mar 2022 16:41:11 +0100 Subject: [PATCH] net: tcp: Verify accept callback before use Closing a listening socket will set the accept callback to NULL. This could lead to a crash, in case an already received packet, finalizing the connection handshake, was processed after the socket was closed. Thereby, it's needed to verify if the callback is actually set before processing it. Signed-off-by: Robert Lubos --- subsys/net/ip/tcp.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/subsys/net/ip/tcp.c b/subsys/net/ip/tcp.c index 44b114582e6..8f1196c62ba 100644 --- a/subsys/net/ip/tcp.c +++ b/subsys/net/ip/tcp.c @@ -1825,11 +1825,13 @@ next_state: NET_CONTEXT_CONNECTED); if (conn->accepted_conn) { - conn->accepted_conn->accept_cb( - conn->context, - &conn->accepted_conn->context->remote, - sizeof(struct sockaddr), 0, - conn->accepted_conn->context); + if (conn->accepted_conn->accept_cb) { + conn->accepted_conn->accept_cb( + conn->context, + &conn->accepted_conn->context->remote, + sizeof(struct sockaddr), 0, + conn->accepted_conn->context); + } /* Make sure the accept_cb is only called once. */