Skip to content

Commit

Permalink
api_msg: Fix potential tcp_abort() thread safety issue
Browse files Browse the repository at this point in the history
2.1.3-esp: 10197b2 api_msg: fix tcp_abort thread safety
  • Loading branch information
david-cermak committed Sep 11, 2024
1 parent 353e8ff commit 9aae28d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 88 deletions.
4 changes: 4 additions & 0 deletions contrib/ports/unix/port/include/arch/cc.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,8 @@ typedef struct sio_status_s sio_status_t;

typedef unsigned int sys_prot_t;

#ifndef __containerof
#define __containerof(ptr, type, member) ((type *)(void *)((char *)ptr - offsetof(type, member)))
#endif

#endif /* LWIP_ARCH_CC_H */
20 changes: 20 additions & 0 deletions src/api/api_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,20 @@ netconn_free(struct netconn *conn)
memp_free(MEMP_NETCONN, conn);
}

#if ESP_LWIP
struct tcp_psb_msg {
struct tcpip_api_call_data call;
struct tcp_pcb *pcb;
};

static err_t tcp_do_abort(struct tcpip_api_call_data *msg)
{
struct tcp_psb_msg *pcb_msg = __containerof(msg, struct tcp_psb_msg, call);
tcp_abort(pcb_msg->pcb);
return ERR_OK;
}
#endif /* ESP_LWIP */

/**
* Delete rcvmbox and acceptmbox of a netconn and free the left-over data in
* these mboxes
Expand Down Expand Up @@ -903,7 +917,13 @@ netconn_drain(struct netconn *conn)
#endif /* ESP_LWIP */
netconn_drain(newconn);
if (newconn->pcb.tcp != NULL) {
#if ESP_LWIP
struct tcp_psb_msg pcb_msg = { 0 };
pcb_msg.pcb = newconn->pcb.tcp;
tcpip_api_call(tcp_do_abort, &pcb_msg.call);
#else
tcp_abort(newconn->pcb.tcp);
#endif /* ESP_LWIP */
newconn->pcb.tcp = NULL;
}
netconn_free(newconn);
Expand Down
88 changes: 0 additions & 88 deletions test/unit/cc_esp_platform.h

This file was deleted.

0 comments on commit 9aae28d

Please sign in to comment.