From cdd57c704b67bda2c4b4b32a4a042c7aa85ef02a Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Mon, 22 Mar 2021 10:37:22 -0400 Subject: [PATCH] Fix #919, check index inside fdset conversions Add an extra limit check for the index, as it is possible due to padding that this goes beyond the end of the array. --- src/os/portable/os-impl-bsd-select.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/os/portable/os-impl-bsd-select.c b/src/os/portable/os-impl-bsd-select.c index dbfb19622..9fb628fd4 100644 --- a/src/os/portable/os-impl-bsd-select.c +++ b/src/os/portable/os-impl-bsd-select.c @@ -88,9 +88,9 @@ static int OS_FdSet_ConvertIn_Impl(fd_set *os_set, OS_FdSet *OSAL_set) bit = 0; while (objids != 0) { - if (objids & 0x01) + id = OSAL_INDEX_C((offset * 8) + bit); + if ((objids & 0x01) != 0 && id < OS_MAX_NUM_OPEN_FILES) { - id = OSAL_INDEX_C((offset * 8) + bit); osfd = OS_impl_filehandle_table[id].fd; if (osfd >= 0 && OS_impl_filehandle_table[id].selectable) { @@ -134,9 +134,9 @@ static void OS_FdSet_ConvertOut_Impl(fd_set *output, OS_FdSet *Input) bit = 0; while (objids != 0) { - if (objids & 0x01) + id = OSAL_INDEX_C((offset * 8) + bit); + if ((objids & 0x01) != 0 && id < OS_MAX_NUM_OPEN_FILES) { - id = OSAL_INDEX_C((offset * 8) + bit); osfd = OS_impl_filehandle_table[id].fd; if (osfd < 0 || !FD_ISSET(osfd, output)) {