Skip to content

Commit

Permalink
Merge pull request #922 from jphickey/fix-921-non-selectable-fd
Browse files Browse the repository at this point in the history
Fix #921, make non-selectable FD an error
  • Loading branch information
astrogeco authored Mar 22, 2021
2 parents 1583e16 + 2b018c0 commit db8ccdc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/os/portable/os-impl-bsd-select.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ static int32 OS_FdSet_ConvertIn_Impl(int *os_maxfd, fd_set *os_set, const OS_FdS
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)
if (osfd >= 0)
{
if (osfd >= FD_SETSIZE)
if (osfd >= FD_SETSIZE || !OS_impl_filehandle_table[id].selectable)
{
/* out of range of select() implementation */
status = OS_ERR_OPERATION_NOT_SUPPORTED;
Expand Down
14 changes: 12 additions & 2 deletions src/unit-test-coverage/portable/src/coveragetest-bsd-select.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,13 @@ void Test_OS_SelectMultiple_Impl(void)
UT_PortablePosixIOTest_Set_Selectable(UT_INDEX_0, true);

memset(&ReadSet, 0, sizeof(ReadSet));
memset(&WriteSet, 0xff, sizeof(WriteSet));
memset(&WriteSet, 0, sizeof(WriteSet));
WriteSet.object_ids[0] = 1;
OSAPI_TEST_FUNCTION_RC(OS_SelectMultiple_Impl, (&ReadSet, &WriteSet, 0), OS_SUCCESS);
memset(&ReadSet, 0xff, sizeof(ReadSet));

memset(&ReadSet, 0, sizeof(ReadSet));
memset(&WriteSet, 0, sizeof(WriteSet));
ReadSet.object_ids[0] = 1;
UT_SetDefaultReturnValue(UT_KEY(OCS_select), 0);
OSAPI_TEST_FUNCTION_RC(OS_SelectMultiple_Impl, (&ReadSet, &WriteSet, 1), OS_ERROR_TIMEOUT);

Expand All @@ -136,6 +139,13 @@ void Test_OS_SelectMultiple_Impl(void)
memset(&WriteSet, 0xff, sizeof(WriteSet));
OSAPI_TEST_FUNCTION_RC(OS_SelectMultiple_Impl, (&ReadSet, &WriteSet, 0), OS_ERR_OPERATION_NOT_SUPPORTED);

/* Test cases where additional bits are set in the OS_FdSet */
UT_PortablePosixIOTest_Set_FD(UT_INDEX_0, 0);
UT_PortablePosixIOTest_Set_Selectable(UT_INDEX_0, true);
memset(&ReadSet, 0xff, sizeof(ReadSet));
memset(&WriteSet, 0xff, sizeof(WriteSet));
OSAPI_TEST_FUNCTION_RC(OS_SelectMultiple_Impl, (&ReadSet, &WriteSet, 0), OS_ERR_OPERATION_NOT_SUPPORTED);

} /* end OS_SelectMultiple_Impl */

/* ------------------- End of test cases --------------------------------------*/
Expand Down

0 comments on commit db8ccdc

Please sign in to comment.