From 3bbea4be672fbb1cdcdc16afd017e03968230615 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Mon, 22 Mar 2021 15:35:36 -0400 Subject: [PATCH] Fix #921, make non-selectable fd an error 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. --- src/os/portable/os-impl-bsd-select.c | 4 ++-- .../portable/src/coveragetest-bsd-select.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/os/portable/os-impl-bsd-select.c b/src/os/portable/os-impl-bsd-select.c index bae652aac..70575e6c9 100644 --- a/src/os/portable/os-impl-bsd-select.c +++ b/src/os/portable/os-impl-bsd-select.c @@ -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; diff --git a/src/unit-test-coverage/portable/src/coveragetest-bsd-select.c b/src/unit-test-coverage/portable/src/coveragetest-bsd-select.c index 653f6aed0..eb88520c4 100644 --- a/src/unit-test-coverage/portable/src/coveragetest-bsd-select.c +++ b/src/unit-test-coverage/portable/src/coveragetest-bsd-select.c @@ -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); @@ -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 --------------------------------------*/