kernel: Fix error for dup2 if the new file descriptor is out of bounds.
authorSascha Wildner <saw@online.de>
Thu, 21 Aug 2014 20:12:01 +0000 (22:12 +0200)
committerSascha Wildner <saw@online.de>
Thu, 21 Aug 2014 20:12:01 +0000 (22:12 +0200)
commit0422901361dc1495e5af3332f7c97aac1f7992ff
treea26d7feb9760cb47f86c7e2f47a57d456dca28e5
parent0e561611b8426a9b32709e5b6880e5f90cc8481a
kernel: Fix error for dup2 if the new file descriptor is out of bounds.

According to POSIX, when using fcntl()'s F_DUPFD or F_DUPFD_CLOEXEC
commands and the new file descriptor is out of bounds, EINVAL must be
returned. But if it is out of bounds when using dup2(), EBADF must be
returned.

So add detection of whether kern_dup() was called from kern_fcntl() or
from sys_dup2() and act accordingly.
sys/kern/kern_descrip.c
sys/sys/kern_syscall.h