From b934c3f4711fca0171e6a7d62c1f47b3d2ffd839 Mon Sep 17 00:00:00 2001 From: goldsimon Date: Mon, 28 Nov 2016 15:50:59 +0100 Subject: [PATCH] fixed bug #49726: setsockopt() set TCP_NODELAY TCP_KEEPALIVE ... with a listen state TCP will crash --- src/api/sockets.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/api/sockets.c b/src/api/sockets.c index 4d2dd656..e493ba6b 100644 --- a/src/api/sockets.c +++ b/src/api/sockets.c @@ -2074,6 +2074,9 @@ lwip_getsockopt_impl(int s, int level, int optname, void *optval, socklen_t *opt case IPPROTO_TCP: /* Special case: all IPPROTO_TCP option take an int */ LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB_TYPE(sock, *optlen, int, NETCONN_TCP); + if (sock->conn->pcb.tcp->state == LISTEN) { + return EINVAL; + } switch (optname) { case TCP_NODELAY: *(int*)optval = tcp_nagle_disabled(sock->conn->pcb.tcp); @@ -2467,6 +2470,9 @@ lwip_setsockopt_impl(int s, int level, int optname, const void *optval, socklen_ case IPPROTO_TCP: /* Special case: all IPPROTO_TCP option take an int */ LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB_TYPE(sock, optlen, int, NETCONN_TCP); + if (sock->conn->pcb.tcp->state == LISTEN) { + return EINVAL; + } switch (optname) { case TCP_NODELAY: if (*(const int*)optval) {