From def2f397246322725c91ef07baf40c23549cfd86 Mon Sep 17 00:00:00 2001 From: Deomid Ryabkov Date: Wed, 24 Nov 2021 02:21:06 +0000 Subject: [PATCH] lwip: Check for accepted connection being NULL This happens when lwip runs out of pcbs and just communicates an error. --- mongoose.c | 4 ++++ src/common/platforms/lwip/mg_lwip_net_if.c | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/mongoose.c b/mongoose.c index d0bb9e85..74d75b78 100644 --- a/mongoose.c +++ b/mongoose.c @@ -15308,6 +15308,10 @@ static err_t mg_lwip_accept_cb(void *arg, struct tcp_pcb *newtpcb, err_t err) { struct mg_connection *lc = (struct mg_connection *) arg, *nc; struct mg_lwip_conn_state *lcs, *cs; struct tcp_pcb_listen *lpcb; + if (newtpcb == NULL) { + LOG(LL_ERROR, ("%p accept error %d", lc, (int) err)); + return ERR_ABRT; + } LOG(LL_DEBUG, ("%p conn %p from %s:%u", lc, newtpcb, IPADDR_NTOA(ipX_2_ip(&newtpcb->remote_ip)), newtpcb->remote_port)); diff --git a/src/common/platforms/lwip/mg_lwip_net_if.c b/src/common/platforms/lwip/mg_lwip_net_if.c index 66c5f8f2..b9e2e067 100644 --- a/src/common/platforms/lwip/mg_lwip_net_if.c +++ b/src/common/platforms/lwip/mg_lwip_net_if.c @@ -383,6 +383,10 @@ static err_t mg_lwip_accept_cb(void *arg, struct tcp_pcb *newtpcb, err_t err) { struct mg_connection *lc = (struct mg_connection *) arg, *nc; struct mg_lwip_conn_state *lcs, *cs; struct tcp_pcb_listen *lpcb; + if (newtpcb == NULL) { + LOG(LL_ERROR, ("%p accept error %d", lc, (int) err)); + return ERR_ABRT; + } LOG(LL_DEBUG, ("%p conn %p from %s:%u", lc, newtpcb, IPADDR_NTOA(ipX_2_ip(&newtpcb->remote_ip)), newtpcb->remote_port));