Skip to content

Commit 1583e16

Browse files
authored
Merge pull request #920 from jphickey/fix-919-fdset-check-id
Fix #919, check index inside fdset conversions
2 parents 0876712 + cdd57c7 commit 1583e16

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/os/portable/os-impl-bsd-select.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ static int32 OS_FdSet_ConvertIn_Impl(int *os_maxfd, fd_set *os_set, const OS_FdS
8888
bit = 0;
8989
while (objids != 0)
9090
{
91-
if (objids & 0x01)
91+
id = OSAL_INDEX_C((offset * 8) + bit);
92+
if ((objids & 0x01) != 0 && id < OS_MAX_NUM_OPEN_FILES)
9293
{
93-
id = OSAL_INDEX_C((offset * 8) + bit);
9494
osfd = OS_impl_filehandle_table[id].fd;
9595
if (osfd >= 0 && OS_impl_filehandle_table[id].selectable)
9696
{
@@ -142,9 +142,9 @@ static void OS_FdSet_ConvertOut_Impl(fd_set *output, OS_FdSet *Input)
142142
bit = 0;
143143
while (objids != 0)
144144
{
145-
if (objids & 0x01)
145+
id = OSAL_INDEX_C((offset * 8) + bit);
146+
if ((objids & 0x01) != 0 && id < OS_MAX_NUM_OPEN_FILES)
146147
{
147-
id = OSAL_INDEX_C((offset * 8) + bit);
148148
osfd = OS_impl_filehandle_table[id].fd;
149149
if (osfd < 0 || !FD_ISSET(osfd, output))
150150
{

0 commit comments

Comments
 (0)