From d68fa86ee18c586c0f022851b9a7fcafa55aa0db Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Wed, 12 Mar 2025 22:01:57 -0400 Subject: [PATCH] libroot/unistd: dup3 should return EINVAL if oldFD == newFD. As per POSIX-2024. Fixes #19476. --- src/system/libroot/posix/unistd/dup.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/system/libroot/posix/unistd/dup.c b/src/system/libroot/posix/unistd/dup.c index c89dc77e4c..e6b00d792a 100644 --- a/src/system/libroot/posix/unistd/dup.c +++ b/src/system/libroot/posix/unistd/dup.c @@ -22,12 +22,14 @@ dup(int fd) int dup2(int oldFD, int newFD) { - return dup3(oldFD, newFD, 0); + RETURN_AND_SET_ERRNO(_kern_dup2(oldFD, newFD, 0)); } int dup3(int oldFD, int newFD, int flags) { + if (oldFD == newFD) + RETURN_AND_SET_ERRNO(EINVAL); RETURN_AND_SET_ERRNO(_kern_dup2(oldFD, newFD, flags)); }