From 715785245c461eb696c181b0e6d09b400f20d0c0 Mon Sep 17 00:00:00 2001 From: chao an Date: Mon, 16 Jan 2023 12:37:44 +0800 Subject: [PATCH] net/tcp: fix potential busy loop in tcp_send_buffered.c if the wrbuffer does not have enough space to send the rest of the data, then the send function will loop infinitely in nonblock mode, add send timeout check to avoid this issue. Signed-off-by: chao an --- net/tcp/tcp_send_buffered.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/tcp/tcp_send_buffered.c b/net/tcp/tcp_send_buffered.c index d7be8d0d8b..925d08bb12 100644 --- a/net/tcp/tcp_send_buffered.c +++ b/net/tcp/tcp_send_buffered.c @@ -1361,7 +1361,8 @@ ssize_t psock_tcp_send(FAR struct socket *psock, FAR const void *buf, tcp_wrbuffer_release(wrb); } - if (nonblock) + if (nonblock || (timeout != UINT_MAX && + tcp_send_gettimeout(start, timeout) == 0)) { nerr("ERROR: Failed to add data to the I/O chain\n"); ret = -EAGAIN;