Skip to content

Commit

Permalink
Merge pull request #1256 from jphickey/fix-1194-check-null
Browse files Browse the repository at this point in the history
Fix #1194, check for NULL in SlotUsed helpers
  • Loading branch information
astrogeco authored Mar 25, 2021
2 parents 0cea6e6 + 739bcea commit fddf17c
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 deletions.
9 changes: 8 additions & 1 deletion modules/es/fsw/src/cfe_es_cds.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,14 @@ int32 CFE_ES_CDSHandle_ToIndex(CFE_ES_CDSHandle_t BlockID, uint32 *Idx)
*/
bool CFE_ES_CheckCDSHandleSlotUsed(CFE_ResourceId_t CheckId)
{
return CFE_ES_CDSBlockRecordIsUsed(CFE_ES_LocateCDSBlockRecordByID(CFE_ES_CDSHANDLE_C(CheckId)));
CFE_ES_CDS_RegRec_t *CDSRegRecPtr;
/*
* Note - The pointer here should never be NULL because the ID should always be
* within the expected range, but if it ever is NULL, this should return true
* such that the caller will _not_ attempt to use the record.
*/
CDSRegRecPtr = CFE_ES_LocateCDSBlockRecordByID(CFE_ES_CDSHANDLE_C(CheckId));
return (CDSRegRecPtr == NULL || CFE_ES_CDSBlockRecordIsUsed(CDSRegRecPtr));
}

/*******************************************************************/
Expand Down
9 changes: 8 additions & 1 deletion modules/es/fsw/src/cfe_es_mempool.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,14 @@ int32 CFE_ES_MemPoolID_ToIndex(CFE_ES_MemHandle_t PoolID, uint32 *Idx)
*/
bool CFE_ES_CheckMemPoolSlotUsed(CFE_ResourceId_t CheckId)
{
return CFE_ES_MemPoolRecordIsUsed(CFE_ES_LocateMemPoolRecordByID(CFE_ES_MEMHANDLE_C(CheckId)));
CFE_ES_MemPoolRecord_t *MemPoolRecPtr;
/*
* Note - The pointer here should never be NULL because the ID should always be
* within the expected range, but if it ever is NULL, this should return true
* such that the caller will _not_ attempt to use the record.
*/
MemPoolRecPtr = CFE_ES_LocateMemPoolRecordByID(CFE_ES_MEMHANDLE_C(CheckId));
return (MemPoolRecPtr == NULL || CFE_ES_MemPoolRecordIsUsed(MemPoolRecPtr));
}

CFE_ES_MemPoolRecord_t *CFE_ES_LocateMemPoolRecordByID(CFE_ES_MemHandle_t PoolID)
Expand Down
27 changes: 24 additions & 3 deletions modules/es/fsw/src/cfe_es_resource.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,14 @@ CFE_ES_AppRecord_t *CFE_ES_GetAppRecordByContext(void)
*/
bool CFE_ES_CheckCounterIdSlotUsed(CFE_ResourceId_t CheckId)
{
return CFE_ES_CounterRecordIsUsed(CFE_ES_LocateCounterRecordByID(CFE_ES_COUNTERID_C(CheckId)));
CFE_ES_GenCounterRecord_t *GenCounterRecPtr;
/*
* Note - The pointer here should never be NULL because the ID should always be
* within the expected range, but if it ever is NULL, this should return true
* such that the caller will _not_ attempt to use the record.
*/
GenCounterRecPtr = CFE_ES_LocateCounterRecordByID(CFE_ES_COUNTERID_C(CheckId));
return (GenCounterRecPtr == NULL || CFE_ES_CounterRecordIsUsed(GenCounterRecPtr));
}

/*
Expand All @@ -370,7 +377,14 @@ bool CFE_ES_CheckCounterIdSlotUsed(CFE_ResourceId_t CheckId)
*/
bool CFE_ES_CheckAppIdSlotUsed(CFE_ResourceId_t CheckId)
{
return CFE_ES_AppRecordIsUsed(CFE_ES_LocateAppRecordByID(CFE_ES_APPID_C(CheckId)));
CFE_ES_AppRecord_t *AppRecPtr;
/*
* Note - The pointer here should never be NULL because the ID should always be
* within the expected range, but if it ever is NULL, this should return true
* such that the caller will _not_ attempt to use the record.
*/
AppRecPtr = CFE_ES_LocateAppRecordByID(CFE_ES_APPID_C(CheckId));
return (AppRecPtr == NULL || CFE_ES_AppRecordIsUsed(AppRecPtr));
}

/*
Expand All @@ -383,5 +397,12 @@ bool CFE_ES_CheckAppIdSlotUsed(CFE_ResourceId_t CheckId)
*/
bool CFE_ES_CheckLibIdSlotUsed(CFE_ResourceId_t CheckId)
{
return CFE_ES_LibRecordIsUsed(CFE_ES_LocateLibRecordByID(CFE_ES_LIBID_C(CheckId)));
CFE_ES_LibRecord_t *LibRecPtr;
/*
* Note - The pointer here should never be NULL because the ID should always be
* within the expected range, but if it ever is NULL, this should return true
* such that the caller will _not_ attempt to use the record.
*/
LibRecPtr = CFE_ES_LocateLibRecordByID(CFE_ES_LIBID_C(CheckId));
return (LibRecPtr == NULL || CFE_ES_LibRecordIsUsed(LibRecPtr));
}
9 changes: 8 additions & 1 deletion modules/sb/fsw/src/cfe_sb_priv.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,14 @@ CFE_SB_PipeD_t *CFE_SB_LocatePipeDescByID(CFE_SB_PipeId_t PipeId)
*/
bool CFE_SB_CheckPipeDescSlotUsed(CFE_ResourceId_t CheckId)
{
return CFE_SB_PipeDescIsUsed(CFE_SB_LocatePipeDescByID(CFE_SB_PIPEID_C(CheckId)));
CFE_SB_PipeD_t *PipeDscPtr;
/*
* Note - The pointer here should never be NULL because the ID should always be
* within the expected range, but if it ever is NULL, this should return true
* such that the caller will _not_ attempt to use the record.
*/
PipeDscPtr = CFE_SB_LocatePipeDescByID(CFE_SB_PIPEID_C(CheckId));
return (PipeDscPtr == NULL || CFE_SB_PipeDescIsUsed(PipeDscPtr));
}

/******************************************************************************
Expand Down

0 comments on commit fddf17c

Please sign in to comment.