Merge pull request #15435 from chrJost/TCP_reset_flag

add nullpointer check in LWIP::socket_close
pull/15436/head
Martin Kojtal 2023-07-11 16:32:31 +02:00 committed by GitHub
commit 13f43cce52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 2 deletions

View File

@ -287,8 +287,9 @@ nsapi_error_t LWIP::socket_close(nsapi_socket_t handle)
/* Check if TCP FSM is in ESTABLISHED state. /* Check if TCP FSM is in ESTABLISHED state.
* Then give extra time for connection close handshaking until TIME_WAIT 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. * 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.*/ * 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) { * 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); _event_flag.clear(TCP_CLOSED_FLAG);
netconn_shutdown(s->conn, false, true); netconn_shutdown(s->conn, false, true);
_event_flag.wait_any(TCP_CLOSED_FLAG, TCP_CLOSE_TIMEOUT); _event_flag.wait_any(TCP_CLOSED_FLAG, TCP_CLOSE_TIMEOUT);