Skip to content

Commit

Permalink
Fix nasa#921, make non-selectable fd an error
Browse files Browse the repository at this point in the history
Do not silently ignore a filehandle which was included in the OS_FdSet
but the "selectable" flag is false.  Instead translate this to
the OS_ERR_OPERATION_NOT_SUPPORTED error.
  • Loading branch information
jphickey committed Mar 22, 2021
1 parent d74e038 commit 3bbea4b
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 3bbea4b

Please sign in to comment.