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.git

commit da93d10843497b4d210b202cf3b3b76a8a91555a
Author: zhaohaiyang1 <[email protected]>
AuthorDate: Mon Jun 29 10:45:28 2026 +0800

    libc/pty: Check the return values of tcsetattr() and ioctl() in openpty().
    
    Coverity CID 95562 reports unchecked return values for tcsetattr()
    and ioctl() calls in openpty(). Add proper error handling: if either
    call fails, close the slave fd and the master fd before returning
    the error.
    
    Signed-off-by: zhaohaiyang1 <[email protected]>
    Signed-off-by: ganjing <[email protected]>
---
 libs/libc/stdlib/lib_openpty.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/libs/libc/stdlib/lib_openpty.c b/libs/libc/stdlib/lib_openpty.c
index 24f74dc5740..733c86909c4 100644
--- a/libs/libc/stdlib/lib_openpty.c
+++ b/libs/libc/stdlib/lib_openpty.c
@@ -172,16 +172,26 @@ int openpty(FAR int *master, FAR int *slave, FAR char 
*name,
 
   if (term != NULL)
     {
-      tcsetattr(*slave, TCSAFLUSH, term);
+      ret = tcsetattr(*slave, TCSAFLUSH, term);
+      if (ret < 0)
+        {
+          goto err_slave;
+        }
     }
 
   if (win != NULL)
     {
-      ioctl(*slave, TIOCSWINSZ, win);
+      ret = ioctl(*slave, TIOCSWINSZ, win);
+      if (ret < 0)
+        {
+          goto err_slave;
+        }
     }
 
   return 0;
 
+err_slave:
+  close(*slave);
 err:
   close(*master);
   return ret;

Reply via email to