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 #1330, better warning about malformed startup line #1370

Merged
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
2 changes: 1 addition & 1 deletion modules/core_private/ut-stubs/src/ut_osprintf_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const char *UT_OSP_MESSAGES[] = {
/* Warning: System Log full, log entry discarded. */
[UT_OSP_SYSTEM_LOG_FULL] = "Warning: System Log full, log entry discarded.\n",
/* ES Startup: ES Startup File Line is too long: 137 bytes. */
[UT_OSP_FILE_LINE_TOO_LONG] = "ES Startup: ES Startup File Line is too long: %u bytes.\n",
[UT_OSP_FILE_LINE_TOO_LONG] = "ES Startup: **WARNING** File Line %u is malformed: %u bytes, %u tokens.\n",
/* ES Startup: Load Shared Library Init Error. */
[UT_OSP_SHARED_LIBRARY_INIT] = "ES Startup: Load Shared Library Init Error = 0x%08x\n",
/* ES Startup: Error Removing Volatile(RAM) Volume. EC = 0x~ */
Expand Down
19 changes: 14 additions & 5 deletions modules/es/fsw/src/cfe_es_apps.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ void CFE_ES_StartApplications(uint32 ResetType, const char *StartFilePath)
char ScriptFileName[OS_MAX_PATH_LEN];
const char *TokenList[CFE_ES_STARTSCRIPT_MAX_TOKENS_PER_LINE];
uint32 NumTokens;
uint32 NumLines;
uint32 BuffLen; /* Length of the current buffer */
osal_id_t AppFile = OS_OBJECT_ID_UNDEFINED;
int32 Status;
Expand Down Expand Up @@ -151,6 +152,7 @@ void CFE_ES_StartApplications(uint32 ResetType, const char *StartFilePath)
memset(ES_AppLoadBuffer, 0x0, ES_START_BUFF_SIZE);
BuffLen = 0;
NumTokens = 0;
NumLines = 0;
TokenList[0] = ES_AppLoadBuffer;

/*
Expand Down Expand Up @@ -197,14 +199,18 @@ void CFE_ES_StartApplications(uint32 ResetType, const char *StartFilePath)
}
BuffLen++;

if (NumTokens < (CFE_ES_STARTSCRIPT_MAX_TOKENS_PER_LINE - 1))
++NumTokens;
if (NumTokens < CFE_ES_STARTSCRIPT_MAX_TOKENS_PER_LINE)
{
/*
* NOTE: pointer never deferenced unless "LineTooLong" is false.
*/
++NumTokens;
TokenList[NumTokens] = &ES_AppLoadBuffer[BuffLen];
}
else
{
LineTooLong = true;
}
}
else if (c != ';')
{
Expand All @@ -223,13 +229,16 @@ void CFE_ES_StartApplications(uint32 ResetType, const char *StartFilePath)
}
else
{
++NumLines;

if (LineTooLong == true)
{
/*
** The was too big for the buffer
** The line was not formed correctly
*/
CFE_ES_WriteToSysLog("ES Startup: ES Startup File Line is too long: %u bytes.\n",
(unsigned int)BuffLen);
CFE_ES_WriteToSysLog(
"ES Startup: **WARNING** File Line %u is malformed: %u bytes, %u tokens.\n",
(unsigned int)NumLines, (unsigned int)BuffLen, (unsigned int)NumTokens);
LineTooLong = false;
}
else
Expand Down
10 changes: 10 additions & 0 deletions modules/es/ut-coverage/es_UT.c
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,16 @@ void TestApps(void)
UtAssert_NONZERO(UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_FILE_LINE_TOO_LONG]));
UtAssert_NONZERO(UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_ES_APP_STARTUP_OPEN]));

/* Test starting an application where the startup script has extra tokens */
ES_ResetUnitTest();
strncpy(StartupScript, "A,B,C,D,E,F,G,H,I,J,K; !", sizeof(StartupScript) - 1);
StartupScript[sizeof(StartupScript) - 1] = '\0';
NumBytes = strlen(StartupScript);
UT_SetReadBuffer(StartupScript, NumBytes);
CFE_ES_StartApplications(CFE_PSP_RST_TYPE_PROCESSOR, "ut_startup");
UtAssert_NONZERO(UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_FILE_LINE_TOO_LONG]));
UtAssert_NONZERO(UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_ES_APP_STARTUP_OPEN]));

/* Create a valid startup script for subsequent tests */
strncpy(StartupScript,
"CFE_LIB, /cf/apps/tst_lib.bundle, TST_LIB_Init, TST_LIB, 0, 0, 0x0, 1; "
Expand Down