Skip to content

Commit 332c8c9

Browse files
committed
fix(mbedtls): Fix already freed and exception bug when ESP8266 as SSL/TLS server
internal gitlab: b216a729
1 parent 13629ab commit 332c8c9

File tree

3 files changed

+24
-18
lines changed

3 files changed

+24
-18
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ phy:
1919
gitlab:
2020
driver : 68fc7b06
2121
lwip : 3267f12f
22-
mbedtls : 83e9034f
22+
mbedtls : e4dace14

lib/libmbedtls.a

120 Bytes
Binary file not shown.

third_party/mbedtls/app/lwIPSocket.c

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -751,24 +751,30 @@ int lwip_close(int s)
751751
{
752752
return -1;
753753
}
754-
755-
if (sock->conn->state != NETCONN_STATE_ERROR){
756-
tcp_recv(sock->conn->tcp, NULL);
757-
err = tcp_close(sock->conn->tcp);
758-
759-
if (err != ERR_OK)
760-
{
761-
/* closing failed, try again later */
762-
tcp_recv(sock->conn->tcp, recv_tcp);
763-
return -1;
764-
}
765-
}
754+
/*Do not set callback function when tcp->state is LISTEN.
755+
Avoid memory overlap when conn->tcp changes from
756+
struct tcp_bcb to struct tcp_pcb_listen after lwip_listen.*/
757+
if (sock->conn->tcp->state != LISTEN)
758+
{
759+
if (sock->conn->state != NETCONN_STATE_ERROR){
760+
tcp_recv(sock->conn->tcp, NULL);
761+
err = tcp_close(sock->conn->tcp);
766762

767-
/* closing succeeded */
768-
remove_tcp(sock->conn);
769-
free_netconn(sock->conn);
770-
free_socket(sock);
771-
return ERR_OK;
763+
if (err != ERR_OK)
764+
{
765+
/* closing failed, try again later */
766+
tcp_recv(sock->conn->tcp, recv_tcp);
767+
return -1;
768+
}
769+
}
770+
/* closing succeeded */
771+
remove_tcp(sock->conn);
772+
} else {
773+
tcp_close(sock->conn->tcp);
774+
}
775+
free_netconn(sock->conn);
776+
free_socket(sock);
777+
return ERR_OK;
772778
}
773779

774780
int lwip_write(int s, const void *data, size_t size)

0 commit comments

Comments
 (0)