hujun260 commented on code in PR #16361:
URL: https://github.com/apache/nuttx/pull/16361#discussion_r2097993216
##########
fs/vfs/fs_dup.c:
##########
@@ -65,29 +65,32 @@ int file_dup(FAR struct file *filep, int minfd, int flags)
uint8_t f_tag_fdcheck; /* File owner fdcheck tag, init to 0 */
#endif
- fd2 = file_allocate(g_root_inode, 0, 0, NULL, minfd, true);
+ /* Pass the close on exec flag to file_allocate */
+
+ fd2 = file_allocate(g_root_inode, flags, 0, NULL, minfd, true);
if (fd2 < 0)
{
return fd2;
}
ret = fs_getfilep(fd2, &filep2);
#ifdef CONFIG_FDSAN
- f_tag_fdsan = filep2->f_tag_fdsan;
+ f_tag_fdsan = nx_fcntl(fd2, NX_GETTAG_FDSAN, 0);
Review Comment:
@pussuw
We designed it by imitating the principle of Google's fdsan.
https://android.googlesource.com/platform/bionic/+/master/docs/fdsan.md
There are some fdsan test cases under this path.
apps/testing/fs/fdsantest
fdcheck, similar to fdsan, is also a tool used to detect whether the
ownership of file descriptors (FDs) is legal. fdcheck can automatically detect
whether the ownership of FDs is legal between processes and within a process.
This helps avoid incorrect FD passing that may lead to misuse, such as using an
FD after it has been freed.
You can also refer to the following test cases.
[fdchecktest.zip](https://github.com/user-attachments/files/20348585/fdchecktest.zip)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]