gazelle/0254-fix-null-pointer-of-sock-in-udp_recvfrom.patch
kircher e8e609cb74 sync enable-UDP-CKSUM-in-gazelle
(cherry picked from commit a02db14a02a694717d7b73914667e7bfcb24f868)
2023-06-26 09:02:31 +08:00

46 lines
1.4 KiB
Diff

From 734f786e959fc536a41f304bbffe9fa9c269b874 Mon Sep 17 00:00:00 2001
From: jiangheng <jiangheng14@huawei.com>
Date: Mon, 19 Jun 2023 15:51:50 +0800
Subject: [PATCH] fix null pointer of sock in udp_recvfrom
---
src/lstack/api/lstack_wrap.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c
index 096fcf7..6ee0512 100644
--- a/src/lstack/api/lstack_wrap.c
+++ b/src/lstack/api/lstack_wrap.c
@@ -552,7 +552,7 @@ static inline ssize_t udp_recvfrom(struct lwip_sock *sock, int32_t sockfd, void
{
int32_t ret;
- do {
+ while (1) {
ret = read_stack_data(sockfd, buf, len, flags, addr, addrlen);
if (ret > 0) {
return ret;
@@ -561,9 +561,16 @@ static inline ssize_t udp_recvfrom(struct lwip_sock *sock, int32_t sockfd, void
return -1;
}
sock = sock->listen_next;
- sockfd = sock->conn->socket;
- } while (sock != NULL);
- GAZELLE_RETURN(EAGAIN);
+ if (sock != NULL && sock->conn != NULL) {
+ sockfd = sock->conn->socket;
+ } else {
+ if (sock == NULL) {
+ GAZELLE_RETURN(EAGAIN);
+ } else {
+ GAZELLE_RETURN(ENOTCONN);
+ }
+ }
+ }
}
static inline ssize_t tcp_recvfrom(struct lwip_sock *sock, int32_t sockfd, void *buf, size_t len, int32_t flags,
--
2.33.0