This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git


The following commit(s) were added to refs/heads/master by this push:
     new fd525988f netutils: smtp: treat recv EOF as an error
fd525988f is described below

commit fd525988f83efeb6433edee7855b86ac1982a7fc
Author: Old-Ding <[email protected]>
AuthorDate: Wed Jul 8 10:51:27 2026 +0800

    netutils: smtp: treat recv EOF as an error
    
    recv() returns zero when the peer closes the TCP connection cleanly. The 
SMTP response path only treated negative returns as errors, so EOF could leave 
stale or empty response data to be checked as if a server reply had arrived.
    
    Return ERROR on zero-length receives at each SMTP response point and keep 
the SPDX copyright header within the project line length limit.
    
    Signed-off-by: Old-Ding <[email protected]>
---
 netutils/smtp/smtp.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/netutils/smtp/smtp.c b/netutils/smtp/smtp.c
index 2a8d23346..e04b65bc0 100644
--- a/netutils/smtp/smtp.c
+++ b/netutils/smtp/smtp.c
@@ -3,7 +3,8 @@
  *
  * SPDX-License-Identifier: BSD-3-Clause
  * SPDX-FileCopyrightText: 2015, 2020 Gregory Nutt. All rights reserved.
- * SPDX-FileCopyrightText: 2007, 2009, 2011, Gregory Nutt. All rights reserved.
+ * SPDX-FileCopyrightText: 2007, 2009, Gregory Nutt. All rights reserved.
+ * SPDX-FileCopyrightText: 2011, Gregory Nutt. All rights reserved.
  * SPDX-FileCopyrightText: 2004, Adam Dunkels. All rights reserved.
  * SPDX-FileContributor: Gregory Nutt <[email protected]>
  * SPDX-FileContributor: Adam Dunkels <[email protected]>
@@ -116,7 +117,7 @@ static const char g_smtpto[]             = "To: ";
 
 static inline int smtp_send_message(int sockfd, struct smtp_state *psmtp)
 {
-  if (recv(sockfd, psmtp->buffer, SMTP_INPUT_BUFFER_SIZE, 0) < 0)
+  if (recv(sockfd, psmtp->buffer, SMTP_INPUT_BUFFER_SIZE, 0) <= 0)
     {
       return ERROR;
     }
@@ -133,7 +134,7 @@ static inline int smtp_send_message(int sockfd, struct 
smtp_state *psmtp)
       return ERROR;
     }
 
-  if (recv(sockfd, psmtp->buffer, SMTP_INPUT_BUFFER_SIZE, 0) < 0)
+  if (recv(sockfd, psmtp->buffer, SMTP_INPUT_BUFFER_SIZE, 0) <= 0)
     {
       return ERROR;
     }
@@ -150,7 +151,7 @@ static inline int smtp_send_message(int sockfd, struct 
smtp_state *psmtp)
       return ERROR;
     }
 
-  if (recv(sockfd, psmtp->buffer, SMTP_INPUT_BUFFER_SIZE, 0) < 0)
+  if (recv(sockfd, psmtp->buffer, SMTP_INPUT_BUFFER_SIZE, 0) <= 0)
     {
       return ERROR;
     }
@@ -167,7 +168,7 @@ static inline int smtp_send_message(int sockfd, struct 
smtp_state *psmtp)
       return ERROR;
     }
 
-  if (recv(sockfd, psmtp->buffer, SMTP_INPUT_BUFFER_SIZE, 0) < 0)
+  if (recv(sockfd, psmtp->buffer, SMTP_INPUT_BUFFER_SIZE, 0) <= 0)
     {
       return ERROR;
     }
@@ -186,7 +187,7 @@ static inline int smtp_send_message(int sockfd, struct 
smtp_state *psmtp)
           return ERROR;
         }
 
-      if (recv(sockfd, psmtp->buffer, SMTP_INPUT_BUFFER_SIZE, 0) < 0)
+      if (recv(sockfd, psmtp->buffer, SMTP_INPUT_BUFFER_SIZE, 0) <= 0)
         {
           return ERROR;
         }
@@ -202,7 +203,7 @@ static inline int smtp_send_message(int sockfd, struct 
smtp_state *psmtp)
       return ERROR;
     }
 
-  if (recv(sockfd, psmtp->buffer, SMTP_INPUT_BUFFER_SIZE, 0) < 0)
+  if (recv(sockfd, psmtp->buffer, SMTP_INPUT_BUFFER_SIZE, 0) <= 0)
     {
       return ERROR;
     }
@@ -254,7 +255,7 @@ static inline int smtp_send_message(int sockfd, struct 
smtp_state *psmtp)
       return ERROR;
     }
 
-  if (recv(sockfd, psmtp->buffer, SMTP_INPUT_BUFFER_SIZE, 0) < 0)
+  if (recv(sockfd, psmtp->buffer, SMTP_INPUT_BUFFER_SIZE, 0) <= 0)
     {
       return ERROR;
     }

Reply via email to