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 <wanggang26@xiaomi.com>
This commit is contained in:
wanggang26 2023-10-25 20:44:15 +08:00 committed by Xiang Xiao
parent f27e755ad7
commit bae15dfd58
2 changed files with 2 additions and 2 deletions

View File

@ -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)

View File

@ -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);