Skip to content

Commit

Permalink
Fix nasa#823, avoid infinite loop in CDS registry find
Browse files Browse the repository at this point in the history
The CFE_ES_FindCDSInRegistry function had an unusual loop control
structure with mixed types of signed and unsigned.

This has the possibility of being infinite if the MaxNumRegEntries
is zero due to the way the end condition is structured.

Simplify to be like other loops and use unsigned int control variable.
  • Loading branch information
jphickey committed Sep 2, 2020
1 parent 08f6eab commit 58ed92e
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions fsw/cfe-core/src/es/cfe_es_cds.c
Original file line number Diff line number Diff line change
Expand Up @@ -637,13 +637,10 @@ int32 CFE_ES_UnlockCDSRegistry(void)
int32 CFE_ES_FindCDSInRegistry(const char *CDSName)
{
int32 RegIndx = CFE_ES_CDS_NOT_FOUND;
int32 i = -1;
uint32 i = 0;

do
while ( (RegIndx == CFE_ES_CDS_NOT_FOUND) && (i < CFE_ES_Global.CDSVars.MaxNumRegEntries) )
{
/* Point to next record in the CDS Registry */
i++;

/* Check to see if the record is currently being used */
if (CFE_ES_Global.CDSVars.Registry[i].Taken == true)
{
Expand All @@ -654,7 +651,11 @@ int32 CFE_ES_FindCDSInRegistry(const char *CDSName)
RegIndx = i;
}
}
} while ( (RegIndx == CFE_ES_CDS_NOT_FOUND) && (i < (CFE_ES_Global.CDSVars.MaxNumRegEntries-1)) );

/* Point to next record in the CDS Registry */
i++;

};

return RegIndx;
} /* End of CFE_ES_FindCDSInRegistry() */
Expand All @@ -670,7 +671,7 @@ int32 CFE_ES_FindCDSInRegistry(const char *CDSName)
int32 CFE_ES_FindFreeCDSRegistryEntry(void)
{
int32 RegIndx = CFE_ES_CDS_NOT_FOUND;
int32 i = 0;
uint32 i = 0;

while ( (RegIndx == CFE_ES_CDS_NOT_FOUND) && (i < CFE_ES_Global.CDSVars.MaxNumRegEntries) )
{
Expand Down

0 comments on commit 58ed92e

Please sign in to comment.