From d1f9ccd5da1712477f30bf2662e8888395ed95cd Mon Sep 17 00:00:00 2001
From: wuchangsheng <wuchangsheng2@huawei.com>
Date: Wed, 21 Jul 2021 20:01:47 +0800
Subject: [PATCH] fix stack-buffer-overflow in lwip_sock_make_addr and
 lwip_getaddrname

---
 src/api/sockets.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/api/sockets.c b/src/api/sockets.c
index 1c3d4a3..3a8a74c 100644
--- a/src/api/sockets.c
+++ b/src/api/sockets.c
@@ -1323,6 +1323,8 @@ lwip_recv_tcp_done:
       add_epoll_event(sock->conn, EPOLLIN);
     }
   }
+#else
+  *fromlen = LWIP_MIN(*fromlen, sizeof(saddr));
 #endif
   set_errno(0);
   return recvd;
@@ -3179,6 +3181,8 @@ lwip_getaddrname(int s, struct sockaddr *name, socklen_t *namelen, u8_t local)
   if (*namelen > IPADDR_SOCKADDR_GET_LEN(&saddr)) {
     *namelen = IPADDR_SOCKADDR_GET_LEN(&saddr);
   }
+#else
+  *namelen = LWIP_MIN(*namelen, sizeof(saddr));
 #endif
   MEMCPY(name, &saddr, *namelen);
 
-- 
2.23.0

