* hinfo.cc (hinfo::dup2): Guard against out of bounds newfd.

This commit is contained in:
Christopher Faylor 2000-06-26 15:27:12 +00:00
parent 84a1af74a2
commit 5a449743bb
2 changed files with 11 additions and 1 deletions

View File

@ -1,3 +1,7 @@
Mon Jun 26 11:25:29 2000 Christopher Faylor <cgf@cygnus.com>
* hinfo.cc (hinfo::dup2): Guard against out of bounds newfd.
Sat Jun 24 23:43:06 2000 Christopher Faylor <cgf@cygnus.com> Sat Jun 24 23:43:06 2000 Christopher Faylor <cgf@cygnus.com>
* grp.cc (read_etc_group): Open file in text mode. * grp.cc (read_etc_group): Open file in text mode.

View File

@ -324,7 +324,7 @@ hinfo::dup2 (int oldfd, int newfd)
if (not_open (oldfd)) if (not_open (oldfd))
{ {
syscall_printf("dup2: fd %d not open", oldfd); syscall_printf ("fd %d not open", oldfd);
set_errno (EBADF); set_errno (EBADF);
goto done; goto done;
} }
@ -342,6 +342,12 @@ hinfo::dup2 (int oldfd, int newfd)
} }
SetResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK,"dup"); SetResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK,"dup");
if (newfd >= dtable.size || newfd < 0)
{
syscall_printf ("new fd out of bounds: %d", newfd);
set_errno (EBADF);
goto done;
}
if (!not_open (newfd)) if (!not_open (newfd))
_close (newfd); _close (newfd);
fds[newfd] = newfh; fds[newfd] = newfh;