mirror of
https://git.rtems.org/rtems-libbsd/
synced 2025-05-14 01:39:57 +08:00
rtemsbsd/libio: Handle invalid descriptors
The documentation for this function suggests that it can handle invalid descriptors safely. This change allows negative descriptors to be handled without a crash.
This commit is contained in:
parent
7cc487f2d3
commit
f0fe0439c4
@ -228,7 +228,7 @@ rtems_bsd_libio_iop_hold(int fd, rtems_libio_t **iopp)
|
||||
rtems_libio_t *iop = NULL;
|
||||
unsigned int flags = 0;
|
||||
int ffd = -1;
|
||||
if (fd < rtems_libio_number_iops) {
|
||||
if (fd >= 0 && fd < rtems_libio_number_iops) {
|
||||
iop = rtems_libio_iop(fd);
|
||||
flags = rtems_libio_iop_hold(iop);
|
||||
if ((flags & LIBIO_FLAGS_OPEN) != 0) {
|
||||
@ -249,7 +249,9 @@ rtems_bsd_libio_iop_hold(int fd, rtems_libio_t **iopp)
|
||||
if (RTEMS_BSD_DESCRIP_TRACE)
|
||||
flags = iop->flags;
|
||||
} else {
|
||||
*iopp = NULL;
|
||||
if (iopp != NULL) {
|
||||
*iopp = NULL;
|
||||
}
|
||||
}
|
||||
if (RTEMS_BSD_DESCRIP_TRACE)
|
||||
printf("bsd: iop: hold: fd=%d ffd=%d refs=%d iop=%p by %p\n",
|
||||
|
Loading…
x
Reference in New Issue
Block a user