From 14a3c35917aa16c21b469aff6e39ae4657f679d2 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Sat, 2 Jan 2021 21:36:31 +0800 Subject: [PATCH] fs: Ensure fs_dupfd2 always return fd2 in the sucessful path it's wrong to return file_dup2 directly since file_dup2 never return file handle Signed-off-by: Xiang Xiao Change-Id: I943537849c75d83b3d646a6a22f035187d9fd521 --- fs/vfs/fs_dupfd2.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fs/vfs/fs_dupfd2.c b/fs/vfs/fs_dupfd2.c index 3ad7aa0c28..d74ccb44e2 100644 --- a/fs/vfs/fs_dupfd2.c +++ b/fs/vfs/fs_dupfd2.c @@ -85,5 +85,11 @@ int fs_dupfd2(int fd1, int fd2) /* Perform the dup2 operation */ - return file_dup2(filep1, filep2); + ret = file_dup2(filep1, filep2); + if (ret < 0) + { + return ret; + } + + return fd2; }