4.104.114.84.95
Last change
on this file since ee733965 was
2d733c42,
checked in by Joel Sherrill <joel.sherrill@…>, on 01/20/99 at 15:48:22
|
More general fix based on bug report and patch from Ian Lance Taylor
<ian@…> to fix this problem:
There is a small bug in rtems_close in c/src/lib/libc/libio.c. It
does not check whether the file descriptor it is passed is open. This
can cause it to make a null dereference if it is passed a file
descriptor which is in the valid range but which was not opened, or
which was already closed.
|
-
Property mode set to
100644
|
File size:
1.4 KB
|
Rev | Line | |
---|
[07a3253d] | 1 | /* |
---|
| 2 | * close() - POSIX 1003.1b 6.3.1 - Close a File |
---|
| 3 | * |
---|
| 4 | * COPYRIGHT (c) 1989-1998. |
---|
| 5 | * On-Line Applications Research Corporation (OAR). |
---|
| 6 | * Copyright assigned to U.S. Government, 1994. |
---|
| 7 | * |
---|
| 8 | * The license and distribution terms for this file may be |
---|
| 9 | * found in the file LICENSE in this distribution or at |
---|
| 10 | * http://www.OARcorp.com/rtems/license.html. |
---|
| 11 | * |
---|
| 12 | * $Id$ |
---|
| 13 | */ |
---|
| 14 | |
---|
| 15 | #include "libio_.h" |
---|
| 16 | |
---|
| 17 | int close( |
---|
| 18 | int fd |
---|
| 19 | ) |
---|
| 20 | { |
---|
| 21 | rtems_libio_t *iop; |
---|
| 22 | rtems_status_code rc; |
---|
| 23 | int status; |
---|
| 24 | |
---|
[cca4400] | 25 | rtems_libio_check_fd(fd); |
---|
| 26 | iop = rtems_libio_iop(fd); |
---|
[2d733c42] | 27 | rtems_libio_check_is_open(iop); |
---|
[cca4400] | 28 | if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) { |
---|
[07a3253d] | 29 | int (*fp)(int fd); |
---|
| 30 | |
---|
[cca4400] | 31 | fp = rtems_libio_handlers[ |
---|
| 32 | (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].close; |
---|
[07a3253d] | 33 | if ( fp == NULL ) |
---|
| 34 | set_errno_and_return_minus_one( EBADF ); |
---|
| 35 | status = (*fp)( fd ); |
---|
| 36 | return status; |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | if ( !iop->handlers ) |
---|
| 40 | set_errno_and_return_minus_one( EBADF ); |
---|
| 41 | |
---|
| 42 | if ( !iop->handlers->close ) |
---|
| 43 | set_errno_and_return_minus_one( ENOTSUP ); |
---|
| 44 | |
---|
| 45 | rc = (*iop->handlers->close)( iop ); |
---|
| 46 | |
---|
| 47 | rtems_libio_free( iop ); |
---|
| 48 | |
---|
| 49 | if (rc != RTEMS_SUCCESSFUL) |
---|
| 50 | set_errno_and_return_minus_one( rc ); |
---|
| 51 | |
---|
| 52 | return rc; |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | /* |
---|
| 56 | * _close_r |
---|
| 57 | * |
---|
| 58 | * This is the Newlib dependent reentrant version of close(). |
---|
| 59 | */ |
---|
| 60 | |
---|
| 61 | #if defined(RTEMS_NEWLIB) |
---|
| 62 | |
---|
| 63 | #include <reent.h> |
---|
| 64 | |
---|
| 65 | int _close_r( |
---|
| 66 | struct _reent *ptr, |
---|
| 67 | int fd |
---|
| 68 | ) |
---|
| 69 | { |
---|
| 70 | return close( fd ); |
---|
| 71 | } |
---|
| 72 | #endif |
---|
Note: See
TracBrowser
for help on using the repository browser.