pussuw commented on code in PR #16326: URL: https://github.com/apache/nuttx/pull/16326#discussion_r2076927066
########## fs/inode/fs_files.c: ########## @@ -317,11 +331,36 @@ static int nx_dup3_from_tcb(FAR struct tcb_s *tcb, int fd1, int fd2, return -EBADF; } + /* dup3() and dup2() dictate that fd2 must be closed prior to reuse */ + + filep = files_fget(list, fd2); + if (filep) + { + /* The file exists and is open, close it here */ + + fs_putfilep(filep); + file_close_wait(filep); + } + + /* This should not fail now */ + filep = files_fget_by_index(list, fd2 / CONFIG_NFILE_DESCRIPTORS_PER_BLOCK, fd2 % CONFIG_NFILE_DESCRIPTORS_PER_BLOCK, &new); + /* If return value is NULL, it means the file is partially open. This means + * the userspace is racing against itself. To prevent the kernel from + * crashing due to access to invalid file pointer, just make the user try Review Comment: 1. Is easily doable, I suggested that we do the retry in libc but we can do it here as well 2. You mean add a file lock to file struct ? -- 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: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org