diff --git a/lib/libc_r/uthread/uthread_dup2.c b/lib/libc_r/uthread/uthread_dup2.c index 6e8195ba17c..af0e32aff5b 100644 --- a/lib/libc_r/uthread/uthread_dup2.c +++ b/lib/libc_r/uthread/uthread_dup2.c @@ -45,7 +45,8 @@ _dup2(int fd, int newfd) int newfd_opened; /* Check if the file descriptor is out of range: */ - if (newfd < 0 || newfd >= _thread_dtablesize) { + if (newfd < 0 || newfd >= _thread_dtablesize || + newfd == _thread_kern_pipe[0] || newfd == _thread_kern_pipe[1]) { /* Return a bad file descriptor error: */ errno = EBADF; ret = -1;