[PATCH rtems-libbsd] rtemsbsd/libio: Handle invalid descriptors
Chris Johns
chrisj at rtems.org
Tue Sep 19 22:13:50 UTC 2023
OK
Thanks
Chris
On 20/9/2023 7:18 am, Kinsey Moore wrote:
> 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 devel
mailing list