From 2d733c424ba21cfa55386e81d668036cc801fc6d Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Wed, 20 Jan 1999 15:48:22 +0000 Subject: More general fix based on bug report and patch from Ian Lance Taylor 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. --- cpukit/include/rtems/libio_.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'cpukit/include/rtems/libio_.h') diff --git a/cpukit/include/rtems/libio_.h b/cpukit/include/rtems/libio_.h index d595500430..995809b6d5 100644 --- a/cpukit/include/rtems/libio_.h +++ b/cpukit/include/rtems/libio_.h @@ -103,6 +103,20 @@ extern mode_t rtems_filesystem_umask; ((((unsigned32)(_fd)) < rtems_libio_number_iops) ? \ &rtems_libio_iops[_fd] : 0) +/* + * rtems_libio_check_is_open + * + * Macro to check if a file descriptor is actually open. + */ + +#define rtems_libio_check_is_open(_iop) \ + do { \ + if (((_iop)->flags & LIBIO_FLAGS_OPEN) == 0) { \ + errno = EBADF; \ + return -1; \ + } \ + } while (0) + /* * rtems_libio_check_fd * @@ -118,7 +132,7 @@ extern mode_t rtems_filesystem_umask; } while (0) /* - * rtems_libio_check_fd + * rtems_libio_check_buffer * * Macro to check if a buffer pointer is valid. */ -- cgit v1.2.3