From aa72f851c3e3e995c40ef309bebb5e3476903923 Mon Sep 17 00:00:00 2001 From: Alex Campbell Date: Wed, 18 Aug 2021 13:29:47 -0400 Subject: [PATCH] Fix #1840, Add Null check for CFE_ResourceId_FindNext --- modules/core_api/fsw/inc/cfe_resourceid.h | 1 + modules/resourceid/fsw/src/cfe_resourceid_api.c | 7 ++++++- modules/resourceid/ut-coverage/test_cfe_resourceid.c | 6 +++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/modules/core_api/fsw/inc/cfe_resourceid.h b/modules/core_api/fsw/inc/cfe_resourceid.h index 98e4e08a0..ed4f85eb6 100644 --- a/modules/core_api/fsw/inc/cfe_resourceid.h +++ b/modules/core_api/fsw/inc/cfe_resourceid.h @@ -200,6 +200,7 @@ uint32 CFE_ResourceId_GetSerial(CFE_ResourceId_t ResourceId); * @param[in] CheckFunc a function to check if the given ID is available * @returns Next ID value which does not map to a valid entry * @retval #CFE_RESOURCEID_UNDEFINED if no open slots. + * @retval #CFE_ES_BAD_ARGUMENT @copybrief CFE_ES_BAD_ARGUMENT * */ CFE_ResourceId_t CFE_ResourceId_FindNext(CFE_ResourceId_t StartId, uint32 TableSize, diff --git a/modules/resourceid/fsw/src/cfe_resourceid_api.c b/modules/resourceid/fsw/src/cfe_resourceid_api.c index 022bb9b86..2c2dd9f52 100644 --- a/modules/resourceid/fsw/src/cfe_resourceid_api.c +++ b/modules/resourceid/fsw/src/cfe_resourceid_api.c @@ -108,7 +108,7 @@ int32 CFE_ResourceId_ToIndex(CFE_ResourceId_t Id, uint32 BaseValue, uint32 Table * * Function: CFE_ResourceId_FindNext * - * Application-scope internal function + * Implemented per public API * See description in header file for argument/return detail * *-----------------------------------------------------------------*/ @@ -121,6 +121,11 @@ CFE_ResourceId_t CFE_ResourceId_FindNext(CFE_ResourceId_t StartId, uint32 TableS CFE_ResourceId_t CheckId; bool IsTaken; + if (CheckFunc == NULL) + { + return CFE_ES_BAD_ARGUMENT; + } + ResourceType = CFE_ResourceId_GetBase(StartId); Serial = CFE_ResourceId_GetSerial(StartId); diff --git a/modules/resourceid/ut-coverage/test_cfe_resourceid.c b/modules/resourceid/ut-coverage/test_cfe_resourceid.c index 8f7952178..4ccc4e13e 100644 --- a/modules/resourceid/ut-coverage/test_cfe_resourceid.c +++ b/modules/resourceid/ut-coverage/test_cfe_resourceid.c @@ -164,10 +164,14 @@ void TestResourceID(void) CFE_ResourceId_ToInteger(Id), (unsigned long)RefIndex, (unsigned long)TestIndex); /* Validate off-nominal inputs */ - Id = CFE_ResourceId_FindNext(CFE_RESOURCEID_UNDEFINED, 0, NULL); + Id = CFE_ResourceId_FindNext(CFE_RESOURCEID_UNDEFINED, 0, UT_ResourceId_CheckIdSlotUsed); UtAssert_True(CFE_ResourceId_Equal(Id, CFE_RESOURCEID_UNDEFINED), "CFE_ResourceId_FindNext() bad input: id=%lx", CFE_ResourceId_ToInteger(Id)); + Id = CFE_ResourceId_FindNext(LastId, 0, NULL); + UtAssert_True(CFE_ResourceId_Equal(Id, CFE_ES_BAD_ARGUMENT), "CFE_ResourceId_FindNext() bad input: id=%lx", + CFE_ResourceId_ToInteger(Id)); + UtAssert_INT32_EQ(CFE_ResourceId_ToIndex(Id, RefBase, 1, NULL), CFE_ES_BAD_ARGUMENT); UtAssert_INT32_EQ(CFE_ResourceId_ToIndex(Id, RefBase, 0, &TestIndex), CFE_ES_ERR_RESOURCEID_NOT_VALID); UtAssert_INT32_EQ(CFE_ResourceId_ToIndex(Id, ~RefBase, 1, &TestIndex), CFE_ES_ERR_RESOURCEID_NOT_VALID);