fs: Fix the race condition in file_dup

NULL inode passed to files_allocate doesn't mark file struct in the
allocated state, so other threads which invovle in file allocation
(e.g. open or dup) may allocate the same file struct again.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: I53ff876eae3c7a1e311e7f671686b73a4b4ef891
This commit is contained in:
Xiang Xiao
2021-01-02 22:08:43 +08:00
committed by archer
parent b343caae4d
commit 86fab49c46
6 changed files with 21 additions and 23 deletions

View File

@@ -269,7 +269,7 @@ static mqd_t nxmq_vopen(FAR const char *mq_name, int oflags, va_list ap)
return ret;
}
ret = files_allocate(mq.f_inode, mq.f_oflags, mq.f_pos, 0);
ret = files_allocate(mq.f_inode, mq.f_oflags, mq.f_pos, mq.f_priv, 0);
if (ret < 0)
{
file_mq_close(&mq);