Skip to content

Commit

Permalink
Fix nasa#1840, Add Null check for CFE_ResourceId_FindNext
Browse files Browse the repository at this point in the history
  • Loading branch information
zanzaben committed Aug 18, 2021
1 parent a0c2de6 commit aa72f85
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions modules/core_api/fsw/inc/cfe_resourceid.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 6 additions & 1 deletion modules/resourceid/fsw/src/cfe_resourceid_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
*-----------------------------------------------------------------*/
Expand All @@ -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);

Expand Down
6 changes: 5 additions & 1 deletion modules/resourceid/ut-coverage/test_cfe_resourceid.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit aa72f85

Please sign in to comment.