From 9b4732f56c7d222c9526443bd3efc83cf2ac7e73 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Wed, 10 Feb 2021 15:46:35 -0500 Subject: [PATCH] Fix #1164, use FS file name parser for commands For commands containing file names, replace the call to CFE_SB_MessageStringGet() - which is just a basic copy - to the new filename-aware function CFE_FS_ParseInputFileName(). This means that the default pathname/extension logic is applied here too and only a "basename" is strictly necessary, although if a full/absolute path is given, it will be used as is. --- modules/es/fsw/src/cfe_es_perf.c | 32 ++-- modules/es/fsw/src/cfe_es_task.c | 189 ++++++++++++++++-------- modules/es/ut-coverage/es_UT.c | 53 ++++++- modules/evs/fsw/src/cfe_evs_log.c | 32 ++-- modules/evs/fsw/src/cfe_evs_task.c | 31 ++-- modules/evs/ut-coverage/evs_UT.c | 14 ++ modules/sb/fsw/src/cfe_sb_task.c | 55 +++++-- modules/sb/ut-coverage/sb_UT.c | 25 ++++ modules/tbl/fsw/src/cfe_tbl_task_cmds.c | 36 +++-- modules/tbl/ut-coverage/tbl_UT.c | 6 + 10 files changed, 352 insertions(+), 121 deletions(-) diff --git a/modules/es/fsw/src/cfe_es_perf.c b/modules/es/fsw/src/cfe_es_perf.c index 76935fa56..d921a4f1a 100644 --- a/modules/es/fsw/src/cfe_es_perf.c +++ b/modules/es/fsw/src/cfe_es_perf.c @@ -203,6 +203,7 @@ int32 CFE_ES_StopPerfDataCmd(const CFE_ES_StopPerfDataCmd_t *data) { const CFE_ES_StopPerfCmd_Payload_t *CmdPtr = &data->Payload; CFE_ES_PerfDumpGlobal_t * PerfDumpState = &CFE_ES_TaskData.BackgroundPerfDumpState; + int32 Status; /* Ensure there is no file write in progress before proceeding */ /* note - also need to check the PendingState here, in case this command @@ -213,19 +214,30 @@ int32 CFE_ES_StopPerfDataCmd(const CFE_ES_StopPerfDataCmd_t *data) Perf->MetaData.State = CFE_ES_PERF_IDLE; /* Copy out the string, using default if unspecified */ - CFE_SB_MessageStringGet(PerfDumpState->DataFileName, CmdPtr->DataFileName, - CFE_PLATFORM_ES_DEFAULT_PERF_DUMP_FILENAME, sizeof(PerfDumpState->DataFileName), - sizeof(CmdPtr->DataFileName)); + Status = CFE_FS_ParseInputFileNameEx(PerfDumpState->DataFileName, CmdPtr->DataFileName, + sizeof(PerfDumpState->DataFileName), sizeof(CmdPtr->DataFileName), + CFE_PLATFORM_ES_DEFAULT_PERF_DUMP_FILENAME, + CFE_FS_GetDefaultMountPoint(CFE_FS_FileCategory_BINARY_DATA_DUMP), + CFE_FS_GetDefaultExtension(CFE_FS_FileCategory_BINARY_DATA_DUMP)); - PerfDumpState->PendingState = CFE_ES_PerfDumpState_INIT; - CFE_ES_BackgroundWakeup(); + if (Status == CFE_SUCCESS) + { + PerfDumpState->PendingState = CFE_ES_PerfDumpState_INIT; + CFE_ES_BackgroundWakeup(); - CFE_ES_TaskData.CommandCounter++; + CFE_ES_TaskData.CommandCounter++; - CFE_EVS_SendEvent(CFE_ES_PERF_STOPCMD_EID, CFE_EVS_EventType_DEBUG, - "Perf Stop Cmd Rcvd, will write %d entries.%dmS dly every %d entries", - (int)Perf->MetaData.DataCount, (int)CFE_PLATFORM_ES_PERF_CHILD_MS_DELAY, - (int)CFE_PLATFORM_ES_PERF_ENTRIES_BTWN_DLYS); + CFE_EVS_SendEvent(CFE_ES_PERF_STOPCMD_EID, CFE_EVS_EventType_DEBUG, + "Perf Stop Cmd Rcvd, will write %d entries.%dmS dly every %d entries", + (int)Perf->MetaData.DataCount, (int)CFE_PLATFORM_ES_PERF_CHILD_MS_DELAY, + (int)CFE_PLATFORM_ES_PERF_ENTRIES_BTWN_DLYS); + } + else + { + CFE_ES_TaskData.CommandErrorCounter++; + CFE_EVS_SendEvent(CFE_ES_PERF_LOG_ERR_EID, CFE_EVS_EventType_ERROR, "Error parsing filename, RC = %d", + (int)Status); + } } /* if data to write == 0 */ else diff --git a/modules/es/fsw/src/cfe_es_task.c b/modules/es/fsw/src/cfe_es_task.c index b9154e9a2..060627ada 100644 --- a/modules/es/fsw/src/cfe_es_task.c +++ b/modules/es/fsw/src/cfe_es_task.c @@ -906,15 +906,16 @@ int32 CFE_ES_StartAppCmd(const CFE_ES_StartAppCmd_t *data) const CFE_ES_StartAppCmd_Payload_t *cmd = &data->Payload; CFE_ES_AppId_t AppID; int32 Result; - int32 FilenameLen; int32 AppEntryLen; int32 AppNameLen; char LocalAppName[OS_MAX_API_NAME]; CFE_ES_AppStartParams_t StartParams; /* Create local copies of all input strings and ensure null termination */ - FilenameLen = CFE_SB_MessageStringGet(StartParams.BasicInfo.FileName, cmd->AppFileName, NULL, - sizeof(StartParams.BasicInfo.FileName), sizeof(cmd->AppFileName)); + Result = CFE_FS_ParseInputFileNameEx(StartParams.BasicInfo.FileName, cmd->AppFileName, + sizeof(StartParams.BasicInfo.FileName), sizeof(cmd->AppFileName), NULL, + CFE_FS_GetDefaultMountPoint(CFE_FS_FileCategory_DYNAMIC_MODULE), + CFE_FS_GetDefaultExtension(CFE_FS_FileCategory_DYNAMIC_MODULE)); AppEntryLen = CFE_SB_MessageStringGet(StartParams.BasicInfo.InitSymbolName, cmd->AppEntryPoint, NULL, sizeof(StartParams.BasicInfo.InitSymbolName), sizeof(cmd->AppEntryPoint)); @@ -925,11 +926,11 @@ int32 CFE_ES_StartAppCmd(const CFE_ES_StartAppCmd_t *data) /* ** Verify command parameters */ - if (FilenameLen < 4) + if (Result != CFE_SUCCESS) { CFE_ES_TaskData.CommandErrorCounter++; CFE_EVS_SendEvent(CFE_ES_START_INVALID_FILENAME_ERR_EID, CFE_EVS_EventType_ERROR, - "CFE_ES_StartAppCmd: invalid filename: %s", StartParams.BasicInfo.FileName); + "CFE_ES_StartAppCmd: invalid filename, status=%lx", (unsigned long)Result); } else if (AppEntryLen <= 0) { @@ -1108,15 +1109,22 @@ int32 CFE_ES_ReloadAppCmd(const CFE_ES_ReloadAppCmd_t *data) CFE_ES_AppId_t AppID; int32 Result; - CFE_SB_MessageStringGet(LocalFileName, (char *)cmd->AppFileName, NULL, sizeof(LocalFileName), - sizeof(cmd->AppFileName)); CFE_SB_MessageStringGet(LocalApp, (char *)cmd->Application, NULL, sizeof(LocalApp), sizeof(cmd->Application)); Result = CFE_ES_GetAppIDByName(&AppID, LocalApp); if (Result == CFE_SUCCESS) { - Result = CFE_ES_ReloadApp(AppID, LocalFileName); + /* Read input string as a file name for dynamic module */ + Result = CFE_FS_ParseInputFileNameEx(LocalFileName, cmd->AppFileName, sizeof(LocalFileName), + sizeof(cmd->AppFileName), NULL, + CFE_FS_GetDefaultMountPoint(CFE_FS_FileCategory_DYNAMIC_MODULE), + CFE_FS_GetDefaultExtension(CFE_FS_FileCategory_DYNAMIC_MODULE)); + + if (Result == CFE_SUCCESS) + { + Result = CFE_ES_ReloadApp(AppID, LocalFileName); + } /* ** Send appropriate event message. @@ -1231,12 +1239,6 @@ int32 CFE_ES_QueryAllCmd(const CFE_ES_QueryAllCmd_t *data) CFE_ES_AppRecord_t * AppRecPtr; CFE_ES_LibRecord_t * LibRecPtr; - /* - ** Copy the commanded filename into local buffer to ensure size limitation and to allow for modification - */ - CFE_SB_MessageStringGet(QueryAllFilename, (char *)CmdPtr->FileName, CFE_PLATFORM_ES_DEFAULT_APP_LOG_FILE, - sizeof(QueryAllFilename), sizeof(CmdPtr->FileName)); - /* * Collect list of active resource IDs. * @@ -1267,21 +1269,31 @@ int32 CFE_ES_QueryAllCmd(const CFE_ES_QueryAllCmd_t *data) } CFE_ES_UnlockSharedData(__func__, __LINE__); - /* - ** Check to see if the file already exists - */ - Result = OS_OpenCreate(&FileDescriptor, QueryAllFilename, OS_FILE_FLAG_NONE, OS_READ_ONLY); - if (Result >= 0) + /* Copy the commanded filename, using default if unspecified */ + Result = CFE_FS_ParseInputFileNameEx(QueryAllFilename, CmdPtr->FileName, sizeof(QueryAllFilename), + sizeof(CmdPtr->FileName), CFE_PLATFORM_ES_DEFAULT_APP_LOG_FILE, + CFE_FS_GetDefaultMountPoint(CFE_FS_FileCategory_BINARY_DATA_DUMP), + CFE_FS_GetDefaultExtension(CFE_FS_FileCategory_BINARY_DATA_DUMP)); + + if (Result == CFE_SUCCESS) { - OS_close(FileDescriptor); - OS_remove(QueryAllFilename); + /* + ** Check to see if the file already exists + */ + Result = OS_OpenCreate(&FileDescriptor, QueryAllFilename, OS_FILE_FLAG_NONE, OS_READ_ONLY); + if (Result >= 0) + { + OS_close(FileDescriptor); + OS_remove(QueryAllFilename); + } + + /* + ** Create ES task log data file + */ + Result = OS_OpenCreate(&FileDescriptor, QueryAllFilename, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, + OS_WRITE_ONLY); } - /* - ** Create ES task log data file - */ - Result = - OS_OpenCreate(&FileDescriptor, QueryAllFilename, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_WRITE_ONLY); if (Result >= 0) { /* @@ -1385,12 +1397,6 @@ int32 CFE_ES_QueryAllTasksCmd(const CFE_ES_QueryAllTasksCmd_t *data) uint32 NumTasks; CFE_ES_TaskRecord_t * TaskRecPtr; - /* - ** Copy the commanded filename into local buffer to ensure size limitation and to allow for modification - */ - CFE_SB_MessageStringGet(QueryAllFilename, (char *)CmdPtr->FileName, CFE_PLATFORM_ES_DEFAULT_TASK_LOG_FILE, - sizeof(QueryAllFilename), sizeof(CmdPtr->FileName)); - /* * Collect list of active task IDs. * @@ -1412,20 +1418,32 @@ int32 CFE_ES_QueryAllTasksCmd(const CFE_ES_QueryAllTasksCmd_t *data) CFE_ES_UnlockSharedData(__func__, __LINE__); /* - ** Check to see if the file already exists + ** Copy the commanded filename into local buffer to ensure size limitation and to allow for modification */ - Result = OS_OpenCreate(&FileDescriptor, QueryAllFilename, OS_FILE_FLAG_NONE, OS_READ_ONLY); - if (Result >= 0) + Result = CFE_FS_ParseInputFileNameEx(QueryAllFilename, CmdPtr->FileName, sizeof(QueryAllFilename), + sizeof(CmdPtr->FileName), CFE_PLATFORM_ES_DEFAULT_TASK_LOG_FILE, + CFE_FS_GetDefaultMountPoint(CFE_FS_FileCategory_BINARY_DATA_DUMP), + CFE_FS_GetDefaultExtension(CFE_FS_FileCategory_BINARY_DATA_DUMP)); + + if (Result == CFE_SUCCESS) { - OS_close(FileDescriptor); - OS_remove(QueryAllFilename); + /* + ** Check to see if the file already exists + */ + Result = OS_OpenCreate(&FileDescriptor, QueryAllFilename, OS_FILE_FLAG_NONE, OS_READ_ONLY); + if (Result >= 0) + { + OS_close(FileDescriptor); + OS_remove(QueryAllFilename); + } + + /* + ** Create ES task log data file + */ + Result = OS_OpenCreate(&FileDescriptor, QueryAllFilename, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, + OS_WRITE_ONLY); } - /* - ** Create ES task log data file - */ - Result = - OS_OpenCreate(&FileDescriptor, QueryAllFilename, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_WRITE_ONLY); if (Result >= 0) { /* @@ -1576,10 +1594,26 @@ int32 CFE_ES_WriteSysLogCmd(const CFE_ES_WriteSysLogCmd_t *data) int32 Stat; char LogFilename[OS_MAX_PATH_LEN]; - CFE_SB_MessageStringGet(LogFilename, (char *)CmdPtr->FileName, CFE_PLATFORM_ES_DEFAULT_SYSLOG_FILE, - sizeof(LogFilename), sizeof(CmdPtr->FileName)); + /* + ** Copy the filename into local buffer with default name/path/extension if not specified + ** + ** Note even though this fundamentally contains strings, it is written as a binary file with an FS header, + ** not as normal text file, so still using the BINARY DATA DUMP category for its default extension. + */ + Stat = CFE_FS_ParseInputFileNameEx(LogFilename, CmdPtr->FileName, sizeof(LogFilename), sizeof(CmdPtr->FileName), + CFE_PLATFORM_ES_DEFAULT_SYSLOG_FILE, + CFE_FS_GetDefaultMountPoint(CFE_FS_FileCategory_BINARY_DATA_DUMP), + CFE_FS_GetDefaultExtension(CFE_FS_FileCategory_BINARY_DATA_DUMP)); - Stat = CFE_ES_SysLogDump(LogFilename); + if (Stat != CFE_SUCCESS) + { + CFE_EVS_SendEvent(CFE_ES_SYSLOG2_ERR_EID, CFE_EVS_EventType_ERROR, "Error parsing file name RC = 0x%08X", + (unsigned int)Stat); + } + else + { + Stat = CFE_ES_SysLogDump(LogFilename); + } if (Stat == CFE_SUCCESS) { @@ -1661,18 +1695,37 @@ int32 CFE_ES_WriteERLogCmd(const CFE_ES_WriteERLogCmd_t *data) StatePtr->FileWrite.GetData = CFE_ES_BackgroundERLogFileDataGetter; StatePtr->FileWrite.OnEvent = CFE_ES_BackgroundERLogFileEventHandler; - CFE_SB_MessageStringGet(StatePtr->FileWrite.FileName, CmdPtr->FileName, CFE_PLATFORM_ES_DEFAULT_ER_LOG_FILE, - sizeof(StatePtr->FileWrite.FileName), sizeof(CmdPtr->FileName)); + /* + ** Copy the filename into local buffer with default name/path/extension if not specified + */ + Status = CFE_FS_ParseInputFileNameEx(StatePtr->FileWrite.FileName, CmdPtr->FileName, + sizeof(StatePtr->FileWrite.FileName), sizeof(CmdPtr->FileName), + CFE_PLATFORM_ES_DEFAULT_ER_LOG_FILE, + CFE_FS_GetDefaultMountPoint(CFE_FS_FileCategory_BINARY_DATA_DUMP), + CFE_FS_GetDefaultExtension(CFE_FS_FileCategory_BINARY_DATA_DUMP)); - Status = CFE_FS_BackgroundFileDumpRequest(&StatePtr->FileWrite); + if (Status == CFE_SUCCESS) + { + Status = CFE_FS_BackgroundFileDumpRequest(&StatePtr->FileWrite); + } } if (Status != CFE_SUCCESS) { - CFE_EVS_SendEvent(CFE_ES_ERLOG_PENDING_ERR_EID, CFE_EVS_EventType_ERROR, - "Error log write to file %s already in progress", StatePtr->FileWrite.FileName); + if (Status == CFE_STATUS_REQUEST_ALREADY_PENDING) + { + /* Specific event if already pending */ + CFE_EVS_SendEvent(CFE_ES_ERLOG_PENDING_ERR_EID, CFE_EVS_EventType_ERROR, + "Error log write already in progress"); + } + else + { + /* Some other validation issue e.g. bad file name */ + CFE_EVS_SendEvent(CFE_ES_ERLOG2_ERR_EID, CFE_EVS_EventType_ERROR, "Error creating file, RC = %d", + (int)Status); + } - /* background dump already running, consider this an error */ + /* background dump did not start, consider this an error */ CFE_ES_TaskData.CommandErrorCounter++; } else @@ -1894,14 +1947,33 @@ int32 CFE_ES_DumpCDSRegistryCmd(const CFE_ES_DumpCDSRegistryCmd_t *data) int32 FileSize = 0; int32 NumEntries = 0; - /* Copy the commanded filename into local buffer to ensure size limitation and to allow for modification */ - CFE_SB_MessageStringGet(DumpFilename, CmdPtr->DumpFilename, CFE_PLATFORM_ES_DEFAULT_CDS_REG_DUMP_FILE, - sizeof(DumpFilename), sizeof(CmdPtr->DumpFilename)); + /* + ** Copy the filename into local buffer with default name/path/extension if not specified + */ + Status = CFE_FS_ParseInputFileNameEx(DumpFilename, CmdPtr->DumpFilename, sizeof(DumpFilename), + sizeof(CmdPtr->DumpFilename), CFE_PLATFORM_ES_DEFAULT_CDS_REG_DUMP_FILE, + CFE_FS_GetDefaultMountPoint(CFE_FS_FileCategory_BINARY_DATA_DUMP), + CFE_FS_GetDefaultExtension(CFE_FS_FileCategory_BINARY_DATA_DUMP)); + + if (Status != OS_SUCCESS) + { + CFE_EVS_SendEvent(CFE_ES_CREATING_CDS_DUMP_ERR_EID, CFE_EVS_EventType_ERROR, + "Error parsing CDS dump filename, Status=0x%08X", (unsigned int)Status); + } + else + { + /* Create a new dump file, overwriting anything that may have existed previously */ + Status = + OS_OpenCreate(&FileDescriptor, DumpFilename, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_WRITE_ONLY); - /* Create a new dump file, overwriting anything that may have existed previously */ - Status = OS_OpenCreate(&FileDescriptor, DumpFilename, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_WRITE_ONLY); + if (Status != OS_SUCCESS) + { + CFE_EVS_SendEvent(CFE_ES_CREATING_CDS_DUMP_ERR_EID, CFE_EVS_EventType_ERROR, + "Error creating CDS dump file '%s', Status=0x%08X", DumpFilename, (unsigned int)Status); + } + } - if (Status >= OS_SUCCESS) + if (Status == OS_SUCCESS) { /* Initialize the standard cFE File Header for the Dump File */ CFE_FS_InitHeader(&StdFileHeader, "CDS_Registry", CFE_FS_SubType_ES_CDS_REG); @@ -1974,9 +2046,6 @@ int32 CFE_ES_DumpCDSRegistryCmd(const CFE_ES_DumpCDSRegistryCmd_t *data) } else { - CFE_EVS_SendEvent(CFE_ES_CREATING_CDS_DUMP_ERR_EID, CFE_EVS_EventType_ERROR, - "Error creating CDS dump file '%s', Status=0x%08X", DumpFilename, (unsigned int)Status); - /* Increment Command Error Counter */ CFE_ES_TaskData.CommandErrorCounter++; } diff --git a/modules/es/ut-coverage/es_UT.c b/modules/es/ut-coverage/es_UT.c index 67e48dc4f..fb2dfc41c 100644 --- a/modules/es/ut-coverage/es_UT.c +++ b/modules/es/ut-coverage/es_UT.c @@ -2348,7 +2348,7 @@ void TestTask(void) UT_Report(__FILE__, __LINE__, UT_EventIsInHistory(CFE_ES_START_ERR_EID), "CFE_ES_StartAppCmd", "Start application from file name fail"); - /* Test app create with the file name too short */ + /* Test app create with an invalid file name */ ES_ResetUnitTest(); memset(&CmdBuf, 0, sizeof(CmdBuf)); strncpy(CmdBuf.StartAppCmd.Payload.AppFileName, "123", sizeof(CmdBuf.StartAppCmd.Payload.AppFileName) - 1); @@ -2361,6 +2361,7 @@ void TestTask(void) CmdBuf.StartAppCmd.Payload.Priority = 160; CmdBuf.StartAppCmd.Payload.StackSize = CFE_ES_MEMOFFSET_C(12096); CmdBuf.StartAppCmd.Payload.ExceptionAction = CFE_ES_ExceptionAction_RESTART_APP; + UT_SetDeferredRetcode(UT_KEY(CFE_FS_ParseInputFileNameEx), 1, CFE_FS_INVALID_PATH); UT_CallTaskPipe(CFE_ES_TaskPipe, &CmdBuf.Msg, sizeof(CmdBuf.StartAppCmd), UT_TPID_CFE_ES_CMD_START_APP_CC); UT_Report(__FILE__, __LINE__, UT_EventIsInHistory(CFE_ES_START_INVALID_FILENAME_ERR_EID), "CFE_ES_StartAppCmd", "Invalid file name"); @@ -2626,6 +2627,14 @@ void TestTask(void) UT_Report(__FILE__, __LINE__, UT_EventIsInHistory(CFE_ES_ALL_APPS_EID), "CFE_ES_QueryAllCmd", "Query all applications - null file name"); + /* Test write of all app data to file with a bad file name */ + ES_ResetUnitTest(); + memset(&CmdBuf, 0, sizeof(CmdBuf)); + UT_SetDeferredRetcode(UT_KEY(CFE_FS_ParseInputFileNameEx), 1, CFE_FS_INVALID_PATH); + UT_CallTaskPipe(CFE_ES_TaskPipe, &CmdBuf.Msg, sizeof(CmdBuf.QueryAllCmd), UT_TPID_CFE_ES_CMD_QUERY_ALL_CC); + UT_Report(__FILE__, __LINE__, UT_EventIsInHistory(CFE_ES_OSCREATE_ERR_EID), "CFE_ES_QueryAllCmd", + "Query all applications - bad file name"); + /* Test write of all app data to file with a write header failure */ ES_ResetUnitTest(); memset(&CmdBuf, 0, sizeof(CmdBuf)); @@ -2661,6 +2670,15 @@ void TestTask(void) UT_Report(__FILE__, __LINE__, UT_EventIsInHistory(CFE_ES_TASKINFO_EID), "CFE_ES_QueryAllTasksCmd", "Task information file written"); + /* Test write of all task data to a file with file name validation failure */ + ES_ResetUnitTest(); + memset(&CmdBuf, 0, sizeof(CmdBuf)); + UT_SetDeferredRetcode(UT_KEY(CFE_FS_ParseInputFileNameEx), 1, CFE_FS_INVALID_PATH); + UT_CallTaskPipe(CFE_ES_TaskPipe, &CmdBuf.Msg, sizeof(CmdBuf.QueryAllTasksCmd), + UT_TPID_CFE_ES_CMD_QUERY_ALL_TASKS_CC); + UT_Report(__FILE__, __LINE__, UT_EventIsInHistory(CFE_ES_TASKINFO_OSCREATE_ERR_EID), "CFE_ES_QueryAllTasksCmd", + "Task information file write fail; OS create"); + /* Test write of all task data to a file with write header failure */ ES_ResetUnitTest(); memset(&CmdBuf, 0, sizeof(CmdBuf)); @@ -2726,6 +2744,14 @@ void TestTask(void) UT_Report(__FILE__, __LINE__, UT_EventIsInHistory(CFE_ES_SYSLOG2_EID), "CFE_ES_WriteSysLogCmd", "Write system log; success"); + /* Test writing the system log using a bad file name */ + ES_ResetUnitTest(); + UT_SetDeferredRetcode(UT_KEY(CFE_FS_ParseInputFileNameEx), 1, CFE_FS_INVALID_PATH); + memset(&CmdBuf, 0, sizeof(CmdBuf)); + UT_CallTaskPipe(CFE_ES_TaskPipe, &CmdBuf.Msg, sizeof(CmdBuf.WriteSysLogCmd), UT_TPID_CFE_ES_CMD_WRITE_SYSLOG_CC); + UT_Report(__FILE__, __LINE__, UT_EventIsInHistory(CFE_ES_SYSLOG2_ERR_EID), "CFE_ES_WriteSysLogCmd", + "Write system log; bad file name"); + /* Test writing the system log using a null file name */ ES_ResetUnitTest(); memset(&CmdBuf, 0, sizeof(CmdBuf)); @@ -2783,6 +2809,13 @@ void TestTask(void) UT_Report(__FILE__, __LINE__, !UT_EventIsInHistory(CFE_ES_ERLOG_PENDING_ERR_EID), "CFE_ES_WriteERLogCmd", "Write E&R log command; no events"); + /* Failure of parsing the file name */ + UT_ClearEventHistory(); + UT_SetDeferredRetcode(UT_KEY(CFE_FS_ParseInputFileNameEx), 1, CFE_FS_INVALID_PATH); + UT_CallTaskPipe(CFE_ES_TaskPipe, &CmdBuf.Msg, sizeof(CmdBuf.WriteERLogCmd), UT_TPID_CFE_ES_CMD_WRITE_ER_LOG_CC); + UT_Report(__FILE__, __LINE__, UT_EventIsInHistory(CFE_ES_ERLOG2_ERR_EID), "CFE_ES_WriteERLogCmd", + "Write E&R log command; bad file name"); + /* Failure from CFE_FS_BackgroundFileDumpRequest() should send the pending error event ID */ UT_ClearEventHistory(); UT_SetDeferredRetcode(UT_KEY(CFE_FS_BackgroundFileDumpRequest), 1, CFE_STATUS_REQUEST_ALREADY_PENDING); @@ -2930,6 +2963,15 @@ void TestTask(void) UT_Report(__FILE__, __LINE__, UT_EventIsInHistory(CFE_ES_CDS_REG_DUMP_INF_EID), "CFE_ES_DumpCDSRegistryCmd", "Dump CDS; success (default dump file)"); + /* Test dumping of the CDS to a file with a bad file name */ + ES_ResetUnitTest(); + memset(&CmdBuf, 0, sizeof(CmdBuf)); + UT_SetDeferredRetcode(UT_KEY(CFE_FS_ParseInputFileNameEx), 1, CFE_FS_INVALID_PATH); + UT_CallTaskPipe(CFE_ES_TaskPipe, &CmdBuf.Msg, sizeof(CmdBuf.DumpCDSRegistryCmd), + UT_TPID_CFE_ES_CMD_DUMP_CDS_REGISTRY_CC); + UT_Report(__FILE__, __LINE__, UT_EventIsInHistory(CFE_ES_CREATING_CDS_DUMP_ERR_EID), "CFE_ES_DumpCDSRegistryCmd", + "Dump CDS; bad file name"); + /* Test dumping of the CDS to a file with a bad FS write header */ ES_ResetUnitTest(); memset(&CmdBuf, 0, sizeof(CmdBuf)); @@ -3287,6 +3329,15 @@ void TestPerf(void) UT_Report(__FILE__, __LINE__, UT_EventIsInHistory(CFE_ES_PERF_STOPCMD_EID), "CFE_ES_StopPerfDataCmd", "Stop collecting performance data"); + /* Test performance data collection stop with a file name validation issue */ + ES_ResetUnitTest(); + memset(&CFE_ES_TaskData.BackgroundPerfDumpState, 0, sizeof(CFE_ES_TaskData.BackgroundPerfDumpState)); + memset(&CmdBuf, 0, sizeof(CmdBuf)); + UT_SetDefaultReturnValue(UT_KEY(CFE_FS_ParseInputFileNameEx), CFE_FS_INVALID_PATH); + UT_CallTaskPipe(CFE_ES_TaskPipe, &CmdBuf.Msg, sizeof(CmdBuf.PerfStopCmd), UT_TPID_CFE_ES_CMD_STOP_PERF_DATA_CC); + UT_Report(__FILE__, __LINE__, UT_EventIsInHistory(CFE_ES_PERF_LOG_ERR_EID), "CFE_ES_StopPerfDataCmd", + "Stop performance data command bad file name"); + /* Test successful performance data collection stop with a non-default file name */ ES_ResetUnitTest(); diff --git a/modules/evs/fsw/src/cfe_evs_log.c b/modules/evs/fsw/src/cfe_evs_log.c index bd665e005..4518364b3 100644 --- a/modules/evs/fsw/src/cfe_evs_log.c +++ b/modules/evs/fsw/src/cfe_evs_log.c @@ -144,20 +144,32 @@ int32 CFE_EVS_WriteLogDataFileCmd(const CFE_EVS_WriteLogDataFileCmd_t *data) CFE_FS_Header_t LogFileHdr; char LogFilename[OS_MAX_PATH_LEN]; - /* Copy the commanded filename into local buffer to ensure size limitation and to allow for modification */ - CFE_SB_MessageStringGet(LogFilename, (const char *)CmdPtr->LogFilename, CFE_PLATFORM_EVS_DEFAULT_LOG_FILE, - sizeof(LogFilename), sizeof(CmdPtr->LogFilename)); - - /* Create the log file */ - Result = OS_OpenCreate(&LogFileHandle, LogFilename, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_WRITE_ONLY); - - if (Result < OS_SUCCESS) + /* + ** Copy the filename into local buffer with default name/path/extension if not specified + */ + Result = CFE_FS_ParseInputFileNameEx(LogFilename, CmdPtr->LogFilename, sizeof(LogFilename), + sizeof(CmdPtr->LogFilename), CFE_PLATFORM_EVS_DEFAULT_LOG_FILE, + CFE_FS_GetDefaultMountPoint(CFE_FS_FileCategory_BINARY_DATA_DUMP), + CFE_FS_GetDefaultExtension(CFE_FS_FileCategory_BINARY_DATA_DUMP)); + + if (Result != OS_SUCCESS) { EVS_SendEvent(CFE_EVS_ERR_CRLOGFILE_EID, CFE_EVS_EventType_ERROR, - "Write Log File Command Error: OS_OpenCreate = 0x%08X, filename = %s", (unsigned int)Result, - LogFilename); + "Write Log File Command Error: CFE_FS_ParseInputFileNameEx() = 0x%08X", (unsigned int)Result); } else + { + /* Create the log file */ + Result = OS_OpenCreate(&LogFileHandle, LogFilename, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_WRITE_ONLY); + if (Result != OS_SUCCESS) + { + EVS_SendEvent(CFE_EVS_ERR_CRLOGFILE_EID, CFE_EVS_EventType_ERROR, + "Write Log File Command Error: OS_OpenCreate = 0x%08X, filename = %s", (unsigned int)Result, + LogFilename); + } + } + + if (Result == OS_SUCCESS) { /* Result will be overridden if everything works */ Result = CFE_EVS_FILE_WRITE_ERROR; diff --git a/modules/evs/fsw/src/cfe_evs_task.c b/modules/evs/fsw/src/cfe_evs_task.c index e225fc0e7..378e3ca14 100644 --- a/modules/evs/fsw/src/cfe_evs_task.c +++ b/modules/evs/fsw/src/cfe_evs_task.c @@ -1693,20 +1693,33 @@ int32 CFE_EVS_WriteAppDataFileCmd(const CFE_EVS_WriteAppDataFileCmd_t *data) const CFE_EVS_AppDataCmd_Payload_t *CmdPtr = &data->Payload; char LocalName[OS_MAX_PATH_LEN]; - /* Copy the commanded filename into local buffer to ensure size limitation and to allow for modification */ - CFE_SB_MessageStringGet(LocalName, CmdPtr->AppDataFilename, CFE_PLATFORM_EVS_DEFAULT_APP_DATA_FILE, - sizeof(LocalName), sizeof(CmdPtr->AppDataFilename)); - - /* Create Application Data File */ - Result = OS_OpenCreate(&FileHandle, LocalName, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_WRITE_ONLY); + /* + ** Copy the filename into local buffer with default name/path/extension if not specified + */ + Result = CFE_FS_ParseInputFileNameEx(LocalName, CmdPtr->AppDataFilename, sizeof(LocalName), + sizeof(CmdPtr->AppDataFilename), CFE_PLATFORM_EVS_DEFAULT_APP_DATA_FILE, + CFE_FS_GetDefaultMountPoint(CFE_FS_FileCategory_BINARY_DATA_DUMP), + CFE_FS_GetDefaultExtension(CFE_FS_FileCategory_BINARY_DATA_DUMP)); - if (Result < OS_SUCCESS) + if (Result != CFE_SUCCESS) { EVS_SendEvent(CFE_EVS_ERR_CRDATFILE_EID, CFE_EVS_EventType_ERROR, - "Write App Data Command Error: OS_OpenCreate = 0x%08X, filename = %s", (unsigned int)Result, - LocalName); + "Write App Data Command Error: CFE_FS_ParseInputFileNameEx() = 0x%08X", (unsigned int)Result); } else + { + /* Create Application Data File */ + Result = OS_OpenCreate(&FileHandle, LocalName, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_WRITE_ONLY); + + if (Result != OS_SUCCESS) + { + EVS_SendEvent(CFE_EVS_ERR_CRDATFILE_EID, CFE_EVS_EventType_ERROR, + "Write App Data Command Error: OS_OpenCreate = 0x%08X, filename = %s", (unsigned int)Result, + LocalName); + } + } + + if (Result == OS_SUCCESS) { /* Result will be overridden if everything works */ Result = CFE_EVS_FILE_WRITE_ERROR; diff --git a/modules/evs/ut-coverage/evs_UT.c b/modules/evs/ut-coverage/evs_UT.c index d863302a4..47a0c78f2 100644 --- a/modules/evs/ut-coverage/evs_UT.c +++ b/modules/evs/ut-coverage/evs_UT.c @@ -1023,6 +1023,12 @@ void Test_Logging(void) UT_Report(__FILE__, __LINE__, CFE_EVS_WriteLogDataFileCmd(&CmdBuf.logfilecmd) == CFE_SUCCESS, "CFE_EVS_WriteLogDataFileCmd", "Write single event log entry - successful (default log name)"); + /* Test writing a log entry with a file name failure */ + UT_InitData(); + UT_SetDeferredRetcode(UT_KEY(CFE_FS_ParseInputFileNameEx), 1, CFE_FS_INVALID_PATH); + UT_Report(__FILE__, __LINE__, CFE_EVS_WriteLogDataFileCmd(&CmdBuf.logfilecmd) != CFE_SUCCESS, + "CFE_EVS_WriteLogDataFileCmd", "FS parse filename failure"); + /* Test writing a log entry with a create failure */ UT_InitData(); UT_SetDeferredRetcode(UT_KEY(OS_MutSemCreate), 1, OS_SUCCESS); @@ -1113,6 +1119,14 @@ void Test_WriteApp(void) UT_Report(__FILE__, __LINE__, UT_EVS_EventBuf.EventID == CFE_EVS_ERR_CRDATFILE_EID, "CFE_EVS_WriteAppDataFileCmd", "OS create fail (default file name)"); + /* Test writing application data with bad file name */ + UT_InitData(); + UT_SetDeferredRetcode(UT_KEY(CFE_FS_ParseInputFileNameEx), 1, CFE_FS_INVALID_PATH); + UT_EVS_DoDispatchCheckEvents(&CmdBuf.AppDataCmd, sizeof(CmdBuf.AppDataCmd), + UT_TPID_CFE_EVS_CMD_WRITE_APP_DATA_FILE_CC, &UT_EVS_EventBuf); + UT_Report(__FILE__, __LINE__, UT_EVS_EventBuf.EventID == CFE_EVS_ERR_CRDATFILE_EID, "CFE_EVS_WriteAppDataFileCmd", + "parse filename failure"); + /* Test writing application data with a write/close failure */ UT_InitData(); UT_SetDefaultReturnValue(UT_KEY(OS_write), OS_ERROR); diff --git a/modules/sb/fsw/src/cfe_sb_task.c b/modules/sb/fsw/src/cfe_sb_task.c index 28dbcd3fe..df2791a29 100644 --- a/modules/sb/fsw/src/cfe_sb_task.c +++ b/modules/sb/fsw/src/cfe_sb_task.c @@ -1022,11 +1022,6 @@ int32 CFE_SB_WriteRoutingInfoCmd(const CFE_SB_WriteRoutingInfoCmd_t *data) /* Reset the entire state object (just for good measure, ensure no stale data) */ memset(StatePtr, 0, sizeof(*StatePtr)); - /* Copy the commanded filename into local buffer to ensure size limitation and to allow for modification */ - CFE_SB_MessageStringGet(StatePtr->FileWrite.FileName, CmdPtr->Filename, - CFE_PLATFORM_SB_DEFAULT_ROUTING_FILENAME, sizeof(StatePtr->FileWrite.FileName), - sizeof(CmdPtr->Filename)); - /* * Fill out the remainder of meta data. * This data is currently the same for every request @@ -1037,7 +1032,19 @@ int32 CFE_SB_WriteRoutingInfoCmd(const CFE_SB_WriteRoutingInfoCmd_t *data) StatePtr->FileWrite.GetData = CFE_SB_WriteRouteInfoDataGetter; StatePtr->FileWrite.OnEvent = CFE_SB_BackgroundFileEventHandler; - Status = CFE_FS_BackgroundFileDumpRequest(&StatePtr->FileWrite); + /* + ** Copy the filename into local buffer with default name/path/extension if not specified + */ + Status = CFE_FS_ParseInputFileNameEx(StatePtr->FileWrite.FileName, CmdPtr->Filename, + sizeof(StatePtr->FileWrite.FileName), sizeof(CmdPtr->Filename), + CFE_PLATFORM_SB_DEFAULT_ROUTING_FILENAME, + CFE_FS_GetDefaultMountPoint(CFE_FS_FileCategory_BINARY_DATA_DUMP), + CFE_FS_GetDefaultExtension(CFE_FS_FileCategory_BINARY_DATA_DUMP)); + + if (Status == CFE_SUCCESS) + { + Status = CFE_FS_BackgroundFileDumpRequest(&StatePtr->FileWrite); + } } else { @@ -1153,10 +1160,6 @@ int32 CFE_SB_WritePipeInfoCmd(const CFE_SB_WritePipeInfoCmd_t *data) /* Reset the entire state object (just for good measure, ensure no stale data) */ memset(StatePtr, 0, sizeof(*StatePtr)); - /* Copy the commanded filename into local buffer to ensure size limitation and to allow for modification */ - CFE_SB_MessageStringGet(StatePtr->FileWrite.FileName, CmdPtr->Filename, CFE_PLATFORM_SB_DEFAULT_PIPE_FILENAME, - sizeof(StatePtr->FileWrite.FileName), sizeof(CmdPtr->Filename)); - /* * Fill out the remainder of meta data. * This data is currently the same for every request @@ -1167,7 +1170,19 @@ int32 CFE_SB_WritePipeInfoCmd(const CFE_SB_WritePipeInfoCmd_t *data) StatePtr->FileWrite.GetData = CFE_SB_WritePipeInfoDataGetter; StatePtr->FileWrite.OnEvent = CFE_SB_BackgroundFileEventHandler; - Status = CFE_FS_BackgroundFileDumpRequest(&StatePtr->FileWrite); + /* + ** Copy the filename into local buffer with default name/path/extension if not specified + */ + Status = CFE_FS_ParseInputFileNameEx(StatePtr->FileWrite.FileName, CmdPtr->Filename, + sizeof(StatePtr->FileWrite.FileName), sizeof(CmdPtr->Filename), + CFE_PLATFORM_SB_DEFAULT_PIPE_FILENAME, + CFE_FS_GetDefaultMountPoint(CFE_FS_FileCategory_BINARY_DATA_DUMP), + CFE_FS_GetDefaultExtension(CFE_FS_FileCategory_BINARY_DATA_DUMP)); + + if (Status == CFE_SUCCESS) + { + Status = CFE_FS_BackgroundFileDumpRequest(&StatePtr->FileWrite); + } } else { @@ -1261,10 +1276,6 @@ int32 CFE_SB_WriteMapInfoCmd(const CFE_SB_WriteMapInfoCmd_t *data) /* Reset the entire state object (just for good measure, ensure no stale data) */ memset(StatePtr, 0, sizeof(*StatePtr)); - /* Copy the commanded filename into local buffer to ensure size limitation and to allow for modification */ - CFE_SB_MessageStringGet(StatePtr->FileWrite.FileName, CmdPtr->Filename, CFE_PLATFORM_SB_DEFAULT_MAP_FILENAME, - sizeof(StatePtr->FileWrite.FileName), sizeof(CmdPtr->Filename)); - /* * Fill out the remainder of meta data. * This data is currently the same for every request @@ -1275,7 +1286,19 @@ int32 CFE_SB_WriteMapInfoCmd(const CFE_SB_WriteMapInfoCmd_t *data) StatePtr->FileWrite.GetData = CFE_SB_WriteMsgMapInfoDataGetter; StatePtr->FileWrite.OnEvent = CFE_SB_BackgroundFileEventHandler; - Status = CFE_FS_BackgroundFileDumpRequest(&StatePtr->FileWrite); + /* + ** Copy the filename into local buffer with default name/path/extension if not specified + */ + Status = CFE_FS_ParseInputFileNameEx(StatePtr->FileWrite.FileName, CmdPtr->Filename, + sizeof(StatePtr->FileWrite.FileName), sizeof(CmdPtr->Filename), + CFE_PLATFORM_SB_DEFAULT_MAP_FILENAME, + CFE_FS_GetDefaultMountPoint(CFE_FS_FileCategory_BINARY_DATA_DUMP), + CFE_FS_GetDefaultExtension(CFE_FS_FileCategory_BINARY_DATA_DUMP)); + + if (Status == CFE_SUCCESS) + { + Status = CFE_FS_BackgroundFileDumpRequest(&StatePtr->FileWrite); + } } else { diff --git a/modules/sb/ut-coverage/sb_UT.c b/modules/sb/ut-coverage/sb_UT.c index 76d530570..dbbe2096d 100644 --- a/modules/sb/ut-coverage/sb_UT.c +++ b/modules/sb/ut-coverage/sb_UT.c @@ -529,6 +529,15 @@ void Test_SB_Cmds_RoutingInfoDef(void) EVTSENT(CFE_SB_SUBSCRIPTION_RCVD_EID); + /* Also test with a bad file name - should generate CFE_SB_SND_RTG_ERR1_EID */ + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &MsgId, sizeof(MsgId), false); + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &Size, sizeof(Size), false); + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false); + UT_SetDeferredRetcode(UT_KEY(CFE_FS_ParseInputFileNameEx), 1, CFE_FS_INVALID_PATH); + CFE_SB_ProcessCmdPipePkt(&WriteRoutingInfo.SBBuf); + + EVTSENT(CFE_SB_SND_RTG_ERR1_EID); + TEARDOWN(CFE_SB_DeletePipe(CFE_SB_Global.CmdPipe)); } /* end Test_SB_Cmds_RoutingInfoDef */ @@ -644,6 +653,14 @@ void Test_SB_Cmds_PipeInfoDef(void) EVTSENT(CFE_SB_PIPE_ADDED_EID); + /* Also test with a bad file name - should generate CFE_SB_SND_RTG_ERR1_EID */ + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &MsgId, sizeof(MsgId), false); + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &Size, sizeof(Size), false); + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false); + UT_SetDeferredRetcode(UT_KEY(CFE_FS_ParseInputFileNameEx), 1, CFE_FS_INVALID_PATH); + CFE_SB_ProcessCmdPipePkt(&WritePipeInfo.SBBuf); + EVTSENT(CFE_SB_SND_RTG_ERR1_EID); + TEARDOWN(CFE_SB_DeletePipe(PipeId1)); TEARDOWN(CFE_SB_DeletePipe(PipeId2)); TEARDOWN(CFE_SB_DeletePipe(PipeId3)); @@ -847,6 +864,14 @@ void Test_SB_Cmds_MapInfoDef(void) EVTSENT(CFE_SB_SUBSCRIPTION_RCVD_EID); + /* Also test with a bad file name - should generate CFE_SB_SND_RTG_ERR1_EID */ + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &MsgId, sizeof(MsgId), false); + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &Size, sizeof(Size), false); + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false); + UT_SetDeferredRetcode(UT_KEY(CFE_FS_ParseInputFileNameEx), 1, CFE_FS_INVALID_PATH); + CFE_SB_ProcessCmdPipePkt(&WriteMapInfo.SBBuf); + EVTSENT(CFE_SB_SND_RTG_ERR1_EID); + TEARDOWN(CFE_SB_DeletePipe(PipeId1)); TEARDOWN(CFE_SB_DeletePipe(PipeId2)); TEARDOWN(CFE_SB_DeletePipe(PipeId3)); diff --git a/modules/tbl/fsw/src/cfe_tbl_task_cmds.c b/modules/tbl/fsw/src/cfe_tbl_task_cmds.c index b3bccb2e8..bfdb59282 100644 --- a/modules/tbl/fsw/src/cfe_tbl_task_cmds.c +++ b/modules/tbl/fsw/src/cfe_tbl_task_cmds.c @@ -1230,11 +1230,6 @@ int32 CFE_TBL_DumpRegistryCmd(const CFE_TBL_DumpRegistryCmd_t *data) /* If a reg dump was already pending, do not overwrite the current request */ if (!CFE_FS_BackgroundFileDumpIsPending(&StatePtr->FileWrite)) { - /* Copy the commanded filename into local buffer to ensure size limitation and to allow for modification */ - CFE_SB_MessageStringGet(StatePtr->FileWrite.FileName, CmdPtr->DumpFilename, - CFE_PLATFORM_TBL_DEFAULT_REG_DUMP_FILE, sizeof(StatePtr->FileWrite.FileName), - sizeof(CmdPtr->DumpFilename)); - /* * Fill out the remainder of meta data. * This data is currently the same for every request @@ -1246,19 +1241,30 @@ int32 CFE_TBL_DumpRegistryCmd(const CFE_TBL_DumpRegistryCmd_t *data) StatePtr->FileWrite.OnEvent = CFE_TBL_DumpRegistryEventHandler; /* - * Before submitting the background request, use OS_stat() to check if the file exists already. - * - * This is because TBL services issued a different event ID in some cases if - * it is overwriting a file vs. creating a new file. - */ - StatePtr->FileExisted = (OS_stat(StatePtr->FileWrite.FileName, &FileStat) == OS_SUCCESS); - - Status = CFE_FS_BackgroundFileDumpRequest(&StatePtr->FileWrite); + ** Copy the filename into local buffer with default name/path/extension if not specified + */ + Status = CFE_FS_ParseInputFileNameEx(StatePtr->FileWrite.FileName, CmdPtr->DumpFilename, + sizeof(StatePtr->FileWrite.FileName), sizeof(CmdPtr->DumpFilename), + CFE_PLATFORM_TBL_DEFAULT_REG_DUMP_FILE, + CFE_FS_GetDefaultMountPoint(CFE_FS_FileCategory_BINARY_DATA_DUMP), + CFE_FS_GetDefaultExtension(CFE_FS_FileCategory_BINARY_DATA_DUMP)); if (Status == CFE_SUCCESS) { - /* Increment the TBL generic command counter (successfully queued for background job) */ - ReturnCode = CFE_TBL_INC_CMD_CTR; + /* + * Before submitting the background request, use OS_stat() to check if the file exists already. + * + * This is because TBL services issued a different event ID in some cases if + * it is overwriting a file vs. creating a new file. + */ + StatePtr->FileExisted = (OS_stat(StatePtr->FileWrite.FileName, &FileStat) == OS_SUCCESS); + + Status = CFE_FS_BackgroundFileDumpRequest(&StatePtr->FileWrite); + if (Status == CFE_SUCCESS) + { + /* Increment the TBL generic command counter (successfully queued for background job) */ + ReturnCode = CFE_TBL_INC_CMD_CTR; + } } } diff --git a/modules/tbl/ut-coverage/tbl_UT.c b/modules/tbl/ut-coverage/tbl_UT.c index 3d788f8a0..233e9cfdf 100644 --- a/modules/tbl/ut-coverage/tbl_UT.c +++ b/modules/tbl/ut-coverage/tbl_UT.c @@ -963,6 +963,12 @@ void Test_CFE_TBL_DumpRegCmd(void) UT_Report(__FILE__, __LINE__, CFE_TBL_DumpRegistryCmd(&DumpRegCmd) == CFE_TBL_INC_CMD_CTR, "CFE_TBL_DumpRegistryCmd", "Default dump file name"); + /* Test command with a bad file name */ + UT_SetDeferredRetcode(UT_KEY(CFE_FS_ParseInputFileNameEx), 1, CFE_FS_INVALID_PATH); + UT_Report(__FILE__, __LINE__, CFE_TBL_DumpRegistryCmd(&DumpRegCmd) == CFE_TBL_INC_ERR_CTR, + "CFE_TBL_DumpRegistryCmd", "Dump file name invalid"); + UT_ResetState(UT_KEY(CFE_FS_ParseInputFileNameEx)); + /* Test command with the dump file already pending (max requests pending) */ UT_SetDefaultReturnValue(UT_KEY(CFE_FS_BackgroundFileDumpIsPending), true); UT_SetDefaultReturnValue(UT_KEY(CFE_FS_BackgroundFileDumpRequest), CFE_STATUS_REQUEST_ALREADY_PENDING);