Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1840, Add Null check for CFE_ResourceId_FindNext #1842

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}

Comment on lines +124 to +128
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest returning CFE_RESOURCEID_UNDEFINED... otherwise this is a conversion from an error code to a resource id type.

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