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 <robert.lubos@nordicsemi.no>
This commit is contained in:
Robert Lubos 2022-03-04 16:41:11 +01:00 committed by Carles Cufí
commit 81b92fcbb3

View file

@ -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.
*/