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:
parent
332d39445c
commit
aa7c6855f7
2 changed files with 1 additions and 5 deletions
|
@ -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;
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in a new issue