From bae15dfd585082b25efbdf892e487570ab339344 Mon Sep 17 00:00:00 2001 From: wanggang26 Date: Wed, 25 Oct 2023 20:44:15 +0800 Subject: [PATCH] nshlib: enable O_CLOEXEC explicit 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 --- nshlib/nsh_script.c | 2 +- nshlib/nsh_syscmds.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/nshlib/nsh_script.c b/nshlib/nsh_script.c index 9cf19fd25..b9a210dff 100644 --- a/nshlib/nsh_script.c +++ b/nshlib/nsh_script.c @@ -119,7 +119,7 @@ int nsh_script(FAR struct nsh_vtbl_s *vtbl, FAR const FAR char *cmd, /* Open the file containing the script */ - vtbl->np.np_fd = open(fullpath, O_RDOK); + vtbl->np.np_fd = open(fullpath, O_RDOK | O_CLOEXEC); if (vtbl->np.np_fd < 0) { if (log) diff --git a/nshlib/nsh_syscmds.c b/nshlib/nsh_syscmds.c index f635a4064..ac14c79ce 100644 --- a/nshlib/nsh_syscmds.c +++ b/nshlib/nsh_syscmds.c @@ -598,7 +598,7 @@ static int cmd_rpmsg_once(FAR struct nsh_vtbl_s *vtbl, return ERROR; } - fd = open(path, 0); + fd = open(path, O_CLOEXEC); if (fd < 0) { nsh_output(vtbl, g_fmtarginvalid, path);