1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00

Return EBADF on negative fds for dup2(2) and dup3(2).

This commit is contained in:
auronandace 2022-02-09 08:08:06 +00:00
parent 332d39445c
commit aa7c6855f7
2 changed files with 1 additions and 5 deletions

View file

@ -231,9 +231,7 @@ int DescriptorTable::Copy(int from, int to, int flags)
if ( flags & ~__FD_ALLOWED_FLAGS ) if ( flags & ~__FD_ALLOWED_FLAGS )
return errno = EINVAL, -1; return errno = EINVAL, -1;
ScopedLock lock(&dtablelock); ScopedLock lock(&dtablelock);
if ( from < 0 || to < 0 ) if ( !IsGoodEntry(from) || to < 0 )
return errno = EINVAL, -1;
if ( !IsGoodEntry(from) )
return errno = EBADF, -1; return errno = EBADF, -1;
if ( from == to ) if ( from == to )
return errno = EINVAL, -1; return errno = EINVAL, -1;

View file

@ -154,8 +154,6 @@ int sys_dup3(int oldfd, int newfd, int flags)
int sys_dup2(int oldfd, int newfd) int sys_dup2(int oldfd, int newfd)
{ {
if ( oldfd < 0 || newfd < 0 )
return errno = EINVAL, -1;
int ret = sys_dup3(oldfd, newfd, 0); int ret = sys_dup3(oldfd, newfd, 0);
if ( ret < 0 && errno == EINVAL ) if ( ret < 0 && errno == EINVAL )
return errno = 0, newfd; return errno = 0, newfd;