[rtems-libbsd commit] rtemsbsd/libio: Handle invalid descriptors
Joel Sherrill
joel at rtems.org
Wed Sep 20 20:25:26 UTC 2023
Module: rtems-libbsd
Branch: 6-freebsd-12
Commit: f0fe0439c494b56e4e044f28584769fcf0ed8143
Changeset: http://git.rtems.org/rtems-libbsd/commit/?id=f0fe0439c494b56e4e044f28584769fcf0ed8143
Author: Kinsey Moore <kinsey.moore at oarcorp.com>
Date: Tue Sep 19 16:02:47 2023 -0500
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.
---
rtemsbsd/include/machine/rtems-bsd-libio.h | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/rtemsbsd/include/machine/rtems-bsd-libio.h b/rtemsbsd/include/machine/rtems-bsd-libio.h
index e662a9ec..8cc67ae3 100644
--- a/rtemsbsd/include/machine/rtems-bsd-libio.h
+++ b/rtemsbsd/include/machine/rtems-bsd-libio.h
@@ -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",
More information about the vc
mailing list