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 )
return errno = EINVAL, -1;
ScopedLock lock(&dtablelock);
if ( from < 0 || to < 0 )
return errno = EINVAL, -1;
if ( !IsGoodEntry(from) )
if ( !IsGoodEntry(from) || to < 0 )
return errno = EBADF, -1;
if ( from == to )
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)
{
if ( oldfd < 0 || newfd < 0 )
return errno = EINVAL, -1;
int ret = sys_dup3(oldfd, newfd, 0);
if ( ret < 0 && errno == EINVAL )
return errno = 0, newfd;