comparison src/w32.c @ 68299:8d40a7886950

(sys_close): If FD is outside [0..MAXDESC) limits, pass it directly to _close. (sys_dup): Protect against new_fd larger than fd_info[] can handle. (sys_read): If FD is outside [0..MAXDESC) limits, pass it directly to _read. (sys_write): If FD is outside [0..MAXDESC) limits, pass it directly to _write.
author Eli Zaretskii <eliz@gnu.org>
date Fri, 20 Jan 2006 19:12:04 +0000
parents 02e47d7a9bca
children 3bd95f4f2941 5b7d410e31f9
comparison
equal deleted inserted replaced
68298:f2e5b42a122e 68299:8d40a7886950
3424 int 3424 int
3425 sys_close (int fd) 3425 sys_close (int fd)
3426 { 3426 {
3427 int rc; 3427 int rc;
3428 3428
3429 if (fd < 0 || fd >= MAXDESC) 3429 if (fd < 0)
3430 { 3430 {
3431 errno = EBADF; 3431 errno = EBADF;
3432 return -1; 3432 return -1;
3433 } 3433 }
3434 3434
3435 if (fd_info[fd].cp) 3435 if (fd < MAXDESC && fd_info[fd].cp)
3436 { 3436 {
3437 child_process * cp = fd_info[fd].cp; 3437 child_process * cp = fd_info[fd].cp;
3438 3438
3439 fd_info[fd].cp = NULL; 3439 fd_info[fd].cp = NULL;
3440 3440
3472 NT and Windows 95 using the standard tcp/ip stacks) - it appears that 3472 NT and Windows 95 using the standard tcp/ip stacks) - it appears that
3473 closesocket is equivalent to CloseHandle, which is to be expected 3473 closesocket is equivalent to CloseHandle, which is to be expected
3474 because socket handles are fully fledged kernel handles. */ 3474 because socket handles are fully fledged kernel handles. */
3475 rc = _close (fd); 3475 rc = _close (fd);
3476 3476
3477 if (rc == 0) 3477 if (rc == 0 && fd < MAXDESC)
3478 fd_info[fd].flags = 0; 3478 fd_info[fd].flags = 0;
3479 3479
3480 return rc; 3480 return rc;
3481 } 3481 }
3482 3482
3484 sys_dup (int fd) 3484 sys_dup (int fd)
3485 { 3485 {
3486 int new_fd; 3486 int new_fd;
3487 3487
3488 new_fd = _dup (fd); 3488 new_fd = _dup (fd);
3489 if (new_fd >= 0) 3489 if (new_fd >= 0 && new_fd < MAXDESC)
3490 { 3490 {
3491 /* duplicate our internal info as well */ 3491 /* duplicate our internal info as well */
3492 fd_info[new_fd] = fd_info[fd]; 3492 fd_info[new_fd] = fd_info[fd];
3493 } 3493 }
3494 return new_fd; 3494 return new_fd;
3639 int nchars; 3639 int nchars;
3640 int to_read; 3640 int to_read;
3641 DWORD waiting; 3641 DWORD waiting;
3642 char * orig_buffer = buffer; 3642 char * orig_buffer = buffer;
3643 3643
3644 if (fd < 0 || fd >= MAXDESC) 3644 if (fd < 0)
3645 { 3645 {
3646 errno = EBADF; 3646 errno = EBADF;
3647 return -1; 3647 return -1;
3648 } 3648 }
3649 3649
3650 if (fd_info[fd].flags & (FILE_PIPE | FILE_SOCKET)) 3650 if (fd < MAXDESC && fd_info[fd].flags & (FILE_PIPE | FILE_SOCKET))
3651 { 3651 {
3652 child_process *cp = fd_info[fd].cp; 3652 child_process *cp = fd_info[fd].cp;
3653 3653
3654 if ((fd_info[fd].flags & FILE_READ) == 0) 3654 if ((fd_info[fd].flags & FILE_READ) == 0)
3655 { 3655 {
3783 int 3783 int
3784 sys_write (int fd, const void * buffer, unsigned int count) 3784 sys_write (int fd, const void * buffer, unsigned int count)
3785 { 3785 {
3786 int nchars; 3786 int nchars;
3787 3787
3788 if (fd < 0 || fd >= MAXDESC) 3788 if (fd < 0)
3789 { 3789 {
3790 errno = EBADF; 3790 errno = EBADF;
3791 return -1; 3791 return -1;
3792 } 3792 }
3793 3793
3794 if (fd_info[fd].flags & (FILE_PIPE | FILE_SOCKET)) 3794 if (fd < MAXDESC && fd_info[fd].flags & (FILE_PIPE | FILE_SOCKET))
3795 { 3795 {
3796 if ((fd_info[fd].flags & FILE_WRITE) == 0) 3796 if ((fd_info[fd].flags & FILE_WRITE) == 0)
3797 { 3797 {
3798 errno = EBADF; 3798 errno = EBADF;
3799 return -1; 3799 return -1;
3831 buffer = tmpbuf; 3831 buffer = tmpbuf;
3832 } 3832 }
3833 } 3833 }
3834 3834
3835 #ifdef HAVE_SOCKETS 3835 #ifdef HAVE_SOCKETS
3836 if (fd_info[fd].flags & FILE_SOCKET) 3836 if (fd < MAXDESC && fd_info[fd].flags & FILE_SOCKET)
3837 { 3837 {
3838 unsigned long nblock = 0; 3838 unsigned long nblock = 0;
3839 if (winsock_lib == NULL) abort (); 3839 if (winsock_lib == NULL) abort ();
3840 3840
3841 /* TODO: implement select() properly so non-blocking I/O works. */ 3841 /* TODO: implement select() properly so non-blocking I/O works. */