From 67d845be32e159c2897a5203b584b00c326c1fc8 Mon Sep 17 00:00:00 2001 From: "Jost, Chris" <79271064+chrJost@users.noreply.github.com> Date: Wed, 5 Jul 2023 11:22:22 +0200 Subject: [PATCH] add nullpointer check in LWIP::socket_close --- connectivity/lwipstack/source/LWIPStack.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/connectivity/lwipstack/source/LWIPStack.cpp b/connectivity/lwipstack/source/LWIPStack.cpp index c67887e62d..210b6e1b75 100644 --- a/connectivity/lwipstack/source/LWIPStack.cpp +++ b/connectivity/lwipstack/source/LWIPStack.cpp @@ -287,8 +287,9 @@ nsapi_error_t LWIP::socket_close(nsapi_socket_t handle) /* Check if TCP FSM is in ESTABLISHED state. * Then give extra time for connection close handshaking until TIME_WAIT state. * The purpose is to prevent eth/wifi driver stop and FIN ACK corrupt. - * This may happend if network interface disconnect follows immediately after socket_close.*/ - if (NETCONNTYPE_GROUP(s->conn->type) == NETCONN_TCP && s->conn->pcb.tcp->state == ESTABLISHED) { + * This may happend if network interface disconnect follows immediately after socket_close. + * In case of a TCP RESET flag, the pcb structure is already deleted, therefore check for nullpointer.*/ + if (NETCONNTYPE_GROUP(s->conn->type) == NETCONN_TCP && (nullptr == s->conn->pcb.tcp || s->conn->pcb.tcp->state == ESTABLISHED)) { _event_flag.clear(TCP_CLOSED_FLAG); netconn_shutdown(s->conn, false, true); _event_flag.wait_any(TCP_CLOSED_FLAG, TCP_CLOSE_TIMEOUT);