From b85282ba08b1fc57e1ef8f408bbb8b3ba0b4835e Mon Sep 17 00:00:00 2001 From: Maxim Konovalov Date: Thu, 14 Feb 2002 15:26:59 +0000 Subject: [PATCH] Prevent dup2(2) from closing internal libc_r pipe descriptors. PR: misc/28947 Reviewed by: jasone, ru Approved by: jasone, ru MFC after: 1 week --- lib/libc_r/uthread/uthread_dup2.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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;