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

xiaoxiang 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 864371cc1 nshlib:enable O_CLOEXEC expliciti to avoid potential fd leak
864371cc1 is described below

commit 864371cc10544df23701ec9471a09a28768af494
Author: wanggang26 <[email protected]>
AuthorDate: Mon Oct 30 18:10:52 2023 +0800

    nshlib:enable O_CLOEXEC expliciti to avoid potential fd leak
    
    leaking here means fork/vfork will duplicate fd without O_CLOEXEC flag
    to the child process.
    
    Signed-off-by: wanggang26 <[email protected]>
---
 nshlib/nsh_fsutils.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/nshlib/nsh_fsutils.c b/nshlib/nsh_fsutils.c
index 4dd8f4141..309f24dc2 100644
--- a/nshlib/nsh_fsutils.c
+++ b/nshlib/nsh_fsutils.c
@@ -82,7 +82,7 @@ static int getpid_callback(FAR struct nsh_vtbl_s *vtbl,
 
   snprintf(buffer, sizeof(buffer), "%s/%s/cmdline", dirpath, entryp->d_name);
 
-  fd = open(buffer, O_RDONLY);
+  fd = open(buffer, O_RDONLY | O_CLOEXEC);
   if (fd < 0)
     {
       return 0;
@@ -137,7 +137,7 @@ int nsh_catfile(FAR struct nsh_vtbl_s *vtbl, FAR const char 
*cmd,
 
   /* Open the file for reading */
 
-  fd = open(filepath, O_RDONLY);
+  fd = open(filepath, O_RDONLY | O_CLOEXEC);
   if (fd < 0)
     {
 #if defined(CONFIG_NSH_PROC_MOUNTPOINT)
@@ -282,7 +282,7 @@ int nsh_readfile(FAR struct nsh_vtbl_s *vtbl, FAR const 
char *cmd,
 
   /* Open the file */
 
-  fd = open(filepath, O_RDONLY);
+  fd = open(filepath, O_RDONLY | O_CLOEXEC);
   if (fd < 0)
     {
       nsh_error(vtbl, g_fmtcmdfailed, cmd, "open", NSH_ERRNO);
@@ -381,7 +381,7 @@ int nsh_writefile(FAR struct nsh_vtbl_s *vtbl, FAR const 
char *cmd,
 
   /* Open the file for reading */
 
-  fd = open(filepath, O_WRONLY);
+  fd = open(filepath, O_WRONLY | O_CLOEXEC);
   if (fd < 0)
     {
 #if defined(CONFIG_NSH_PROC_MOUNTPOINT)

Reply via email to