tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[PATCH] dup2() should return proper error code



When new file descriptor passed to dup2() is out of range the dup2() system
call doesn't return proper error.  Actually the SUSv3 requires correct error
handling:
"If fildes2 is less than 0 or greater than or equal to {OPEN_MAX}, dup2() shall
return -1 with errno set to [EBADF]."

Manual page is leaved the same due to appropriate description of the dup2()
behaviour.
---
 sys/kern/sys_descrip.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/sys/kern/sys_descrip.c b/sys/kern/sys_descrip.c
index 976e653..9a083ea 100644
--- a/sys/kern/sys_descrip.c
+++ b/sys/kern/sys_descrip.c
@@ -127,7 +127,7 @@ sys_dup2(struct lwp *l, const struct sys_dup2_args *uap, 
register_t *retval)
                syscallarg(int) from;
                syscallarg(int) to;
        } */
-       int old, new, error;
+       int old, new, error = 0;
        file_t *fp;
 
        old = SCARG(uap, from);
@@ -147,7 +147,7 @@ sys_dup2(struct lwp *l, const struct sys_dup2_args *uap, 
register_t *retval)
        fd_putfile(old);
        *retval = new;
 
-       return 0;
+       return error;
 }
 
 /*
-- 
1.5.2.5



Home | Main Index | Thread Index | Old Index