Fix 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.
@@ -87,10 +87,10 @@ static int OS_FdSet_ConvertIn_Impl(fd_set *os_set, OS_FdSet *OSAL_set)
objids = OSAL_set->object_ids[offset];
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)
+ {
osfd = OS_impl_filehandle_table[id].fd;
if (osfd >= 0 && OS_impl_filehandle_table[id].selectable)
{
@@ -133,10 +133,10 @@ static void OS_FdSet_ConvertOut_Impl(fd_set *output, OS_FdSet *Input)
objids = Input->object_ids[offset];
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)
+ {
osfd = OS_impl_filehandle_table[id].fd;
if (osfd < 0 || !FD_ISSET(osfd, output))
{
