From 0a343948d9446fcbe2290d411e526d826f55fb83 Mon Sep 17 00:00:00 2001 From: sg Date: Fri, 7 Oct 2016 21:46:26 +0200 Subject: [PATCH] Fix netconn/socket race condition when receiving RST while waiting on recvmbox --- src/api/api_lib.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/api/api_lib.c b/src/api/api_lib.c index 193a608f..b4fc403d 100644 --- a/src/api/api_lib.c +++ b/src/api/api_lib.c @@ -544,6 +544,10 @@ netconn_recv_data(struct netconn *conn, void **new_buf) /* If we are closed, we indicate that we no longer wish to use the socket */ if (buf == NULL) { API_EVENT(conn, NETCONN_EVT_RCVMINUS, 0); + if (conn->pcb.ip == NULL) { + /* race condition: RST during recv */ + return conn->last_err == ERR_OK ? ERR_RST : conn->last_err; + } /* RX side is closed, so deallocate the recvmbox */ netconn_close_shutdown(conn, NETCONN_SHUT_RD); /* Don' store ERR_CLSD as conn->err since we are only half-closed */