Skip to content

Commit

Permalink
Merge pull request nasa#74 from chillfig/AmendConstCast
Browse files Browse the repository at this point in the history
Fix nasa#66, Adds local variables for command buffer processing
  • Loading branch information
dzbaker committed May 12, 2023
2 parents 823599a + 22594b8 commit da7ef70
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 129 deletions.
55 changes: 25 additions & 30 deletions fsw/src/mm_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -420,11 +420,12 @@ bool MM_ResetCmd(const CFE_SB_Buffer_t *BufPtr)
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
bool MM_LookupSymbolCmd(const CFE_SB_Buffer_t *BufPtr)
{
int32 OS_Status = OS_ERROR; /* Set to error instead of success since we explicitly test for success */
cpuaddr ResolvedAddr = 0;
MM_LookupSymCmd_t *CmdPtr = NULL;
size_t ExpectedLength = sizeof(MM_LookupSymCmd_t);
bool Result = false;
int32 OS_Status = OS_ERROR; /* Set to error instead of success since we explicitly test for success */
cpuaddr ResolvedAddr = 0;
const MM_LookupSymCmd_t *CmdPtr = NULL;
size_t ExpectedLength = sizeof(MM_LookupSymCmd_t);
bool Result = false;
char SymName[OS_MAX_SYM_LEN];

/*
** Verify command packet length
Expand All @@ -433,16 +434,13 @@ bool MM_LookupSymbolCmd(const CFE_SB_Buffer_t *BufPtr)
{
CmdPtr = ((MM_LookupSymCmd_t *)BufPtr);

/*
** NUL terminate the very end of the symbol name string as a
** safety measure
*/
CmdPtr->SymName[OS_MAX_SYM_LEN - 1] = '\0';
/* Make sure string is null terminated before attempting to process it */
CFE_SB_MessageStringGet(SymName, CmdPtr->SymName, NULL, sizeof(SymName), sizeof(CmdPtr->SymName));

/*
** Check if the symbol name string is a nul string
*/
if (strlen(CmdPtr->SymName) == 0)
if (strlen(SymName) == 0)
{
CFE_EVS_SendEvent(MM_SYMNAME_NUL_ERR_EID, CFE_EVS_EventType_ERROR,
"NUL (empty) string specified as symbol name");
Expand All @@ -452,22 +450,21 @@ bool MM_LookupSymbolCmd(const CFE_SB_Buffer_t *BufPtr)
/*
** If symbol name is not an empty string look it up using the OSAL API
*/
OS_Status = OS_SymbolLookup(&ResolvedAddr, CmdPtr->SymName);
OS_Status = OS_SymbolLookup(&ResolvedAddr, SymName);
if (OS_Status == OS_SUCCESS)
{
/* Update telemetry */
MM_AppData.HkPacket.LastAction = MM_SYM_LOOKUP;
MM_AppData.HkPacket.Address = ResolvedAddr;

CFE_EVS_SendEvent(MM_SYM_LOOKUP_INF_EID, CFE_EVS_EventType_INFORMATION,
"Symbol Lookup Command: Name = '%s' Addr = %p", CmdPtr->SymName,
(void *)ResolvedAddr);
"Symbol Lookup Command: Name = '%s' Addr = %p", SymName, (void *)ResolvedAddr);
Result = true;
}
else
{
CFE_EVS_SendEvent(MM_SYMNAME_ERR_EID, CFE_EVS_EventType_ERROR,
"Symbolic address can't be resolved: Name = '%s'", CmdPtr->SymName);
"Symbolic address can't be resolved: Name = '%s'", SymName);
}

} /* end strlen(CmdPtr->SymName) == 0 else */
Expand All @@ -484,10 +481,11 @@ bool MM_LookupSymbolCmd(const CFE_SB_Buffer_t *BufPtr)
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
bool MM_SymTblToFileCmd(const CFE_SB_Buffer_t *BufPtr)
{
int32 OS_Status = OS_ERROR; /* Set to error instead of success since we explicitly test for success */
MM_SymTblToFileCmd_t *CmdPtr = NULL;
size_t ExpectedLength = sizeof(MM_SymTblToFileCmd_t);
bool Result = false;
int32 OS_Status = OS_ERROR; /* Set to error instead of success since we explicitly test for success */
char FileName[OS_MAX_PATH_LEN];
const MM_SymTblToFileCmd_t *CmdPtr = NULL;
size_t ExpectedLength = sizeof(MM_SymTblToFileCmd_t);
bool Result = false;

/*
** Verify command packet length
Expand All @@ -496,41 +494,38 @@ bool MM_SymTblToFileCmd(const CFE_SB_Buffer_t *BufPtr)
{
CmdPtr = ((MM_SymTblToFileCmd_t *)BufPtr);

/*
** NUL terminate the very end of the filename string as a
** safety measure
*/
CmdPtr->FileName[OS_MAX_PATH_LEN - 1] = '\0';
/* Make sure string is null terminated before attempting to process it */
CFE_SB_MessageStringGet(FileName, CmdPtr->FileName, NULL, sizeof(FileName), sizeof(CmdPtr->FileName));

/*
** Check if the filename string is a nul string
*/
if (strlen(CmdPtr->FileName) == 0)
if (strlen(FileName) == 0)
{
CFE_EVS_SendEvent(MM_SYMFILENAME_NUL_ERR_EID, CFE_EVS_EventType_ERROR,
"NUL (empty) string specified as symbol dump file name");
}
else
{
OS_Status = OS_SymbolTableDump(CmdPtr->FileName, MM_MAX_DUMP_FILE_DATA_SYMTBL);
OS_Status = OS_SymbolTableDump(FileName, MM_MAX_DUMP_FILE_DATA_SYMTBL);
if (OS_Status == OS_SUCCESS)
{
/* Update telemetry */
MM_AppData.HkPacket.LastAction = MM_SYMTBL_SAVE;
strncpy(MM_AppData.HkPacket.FileName, CmdPtr->FileName, OS_MAX_PATH_LEN);
strncpy(MM_AppData.HkPacket.FileName, FileName, OS_MAX_PATH_LEN);

CFE_EVS_SendEvent(MM_SYMTBL_TO_FILE_INF_EID, CFE_EVS_EventType_INFORMATION,
"Symbol Table Dump to File Started: Name = '%s'", CmdPtr->FileName);
"Symbol Table Dump to File Started: Name = '%s'", FileName);
Result = true;
}
else
{
CFE_EVS_SendEvent(MM_SYMTBL_TO_FILE_FAIL_ERR_EID, CFE_EVS_EventType_ERROR,
"Error dumping symbol table, OS_Status= 0x%X, File='%s'", (unsigned int)OS_Status,
CmdPtr->FileName);
FileName);
}

} /* end strlen(CmdPtr->FileName) == 0 else */
} /* end strlen(FileName) == 0 else */

} /* end MM_VerifyCmdLength if */

Expand Down
101 changes: 53 additions & 48 deletions fsw/src/mm_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,22 @@ extern MM_AppData_t MM_AppData;
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
bool MM_PeekCmd(const CFE_SB_Buffer_t *BufPtr)
{
bool Valid;
MM_PeekCmd_t *CmdPtr;
cpuaddr SrcAddress = 0;
uint16 ExpectedLength = sizeof(MM_PeekCmd_t);
bool Result = false;
bool Valid;
const MM_PeekCmd_t *CmdPtr;
cpuaddr SrcAddress = 0;
uint16 ExpectedLength = sizeof(MM_PeekCmd_t);
bool Result = false;
MM_SymAddr_t SrcSymAddress;

/* Verify command packet length */
if (MM_VerifyCmdLength(&BufPtr->Msg, ExpectedLength))
{
CmdPtr = ((MM_PeekCmd_t *)BufPtr);

SrcSymAddress = CmdPtr->SrcSymAddress;

/* Resolve the symbolic address in command message */
Valid = MM_ResolveSymAddr(&(CmdPtr->SrcSymAddress), &SrcAddress);
Valid = MM_ResolveSymAddr(&(SrcSymAddress), &SrcAddress);

if (Valid == true)
{
Expand Down Expand Up @@ -186,28 +189,29 @@ bool MM_PeekMem(const MM_PeekCmd_t *CmdPtr, cpuaddr SrcAddress)
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
bool MM_DumpMemToFileCmd(const CFE_SB_Buffer_t *BufPtr)
{
bool Valid = false;
int32 OS_Status;
osal_id_t FileHandle = OS_OBJECT_ID_UNDEFINED;
cpuaddr SrcAddress = 0;
MM_DumpMemToFileCmd_t * CmdPtr;
CFE_FS_Header_t CFEFileHeader;
MM_LoadDumpFileHeader_t MMFileHeader;
uint16 ExpectedLength = sizeof(MM_DumpMemToFileCmd_t);
bool Valid = false;
int32 OS_Status;
osal_id_t FileHandle = OS_OBJECT_ID_UNDEFINED;
cpuaddr SrcAddress = 0;
char FileName[OS_MAX_PATH_LEN];
MM_SymAddr_t SrcSymAddress;
const MM_DumpMemToFileCmd_t *CmdPtr;
CFE_FS_Header_t CFEFileHeader;
MM_LoadDumpFileHeader_t MMFileHeader;
uint16 ExpectedLength = sizeof(MM_DumpMemToFileCmd_t);

/* Verify command packet length */
if (MM_VerifyCmdLength(&BufPtr->Msg, ExpectedLength))
{
CmdPtr = ((MM_DumpMemToFileCmd_t *)BufPtr);

/*
** NUL terminate the very end of the file name string array as a
** safety measure
*/
CmdPtr->FileName[OS_MAX_PATH_LEN - 1] = '\0';
SrcSymAddress = CmdPtr->SrcSymAddress;

/* Make sure strings are null terminated before attempting to process them */
CFE_SB_MessageStringGet(FileName, CmdPtr->FileName, NULL, sizeof(FileName), sizeof(CmdPtr->FileName));

/* Resolve the symbolic address in command message */
Valid = MM_ResolveSymAddr(&(CmdPtr->SrcSymAddress), &SrcAddress);
Valid = MM_ResolveSymAddr(&(SrcSymAddress), &SrcAddress);

if (Valid == true)
{
Expand Down Expand Up @@ -237,36 +241,36 @@ bool MM_DumpMemToFileCmd(const CFE_SB_Buffer_t *BufPtr)
/*
** Create and open dump file
*/
OS_Status = OS_OpenCreate(&FileHandle, CmdPtr->FileName, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE,
OS_READ_WRITE);
OS_Status =
OS_OpenCreate(&FileHandle, FileName, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE);
if (OS_Status == OS_SUCCESS)
{
/* Write the file headers */
Valid = MM_WriteFileHeaders(CmdPtr->FileName, FileHandle, &CFEFileHeader, &MMFileHeader);
Valid = MM_WriteFileHeaders(FileName, FileHandle, &CFEFileHeader, &MMFileHeader);
if (Valid == true)
{
switch (MMFileHeader.MemType)
{
case MM_RAM:
case MM_EEPROM:
Valid = MM_DumpMemToFile(FileHandle, CmdPtr->FileName, &MMFileHeader);
Valid = MM_DumpMemToFile(FileHandle, FileName, &MMFileHeader);
break;

#ifdef MM_OPT_CODE_MEM32_MEMTYPE
case MM_MEM32:
Valid = MM_DumpMem32ToFile(FileHandle, CmdPtr->FileName, &MMFileHeader);
Valid = MM_DumpMem32ToFile(FileHandle, FileName, &MMFileHeader);
break;
#endif /* MM_OPT_CODE_MEM32_MEMTYPE */

#ifdef MM_OPT_CODE_MEM16_MEMTYPE
case MM_MEM16:
Valid = MM_DumpMem16ToFile(FileHandle, CmdPtr->FileName, &MMFileHeader);
Valid = MM_DumpMem16ToFile(FileHandle, FileName, &MMFileHeader);
break;
#endif /* MM_OPT_CODE_MEM16_MEMTYPE */

#ifdef MM_OPT_CODE_MEM8_MEMTYPE
case MM_MEM8:
Valid = MM_DumpMem8ToFile(FileHandle, CmdPtr->FileName, &MMFileHeader);
Valid = MM_DumpMem8ToFile(FileHandle, FileName, &MMFileHeader);
break;
#endif /* MM_OPT_CODE_MEM8_MEMTYPE */
default:
Expand Down Expand Up @@ -298,16 +302,15 @@ bool MM_DumpMemToFileCmd(const CFE_SB_Buffer_t *BufPtr)
** the file pointer to the beginning of the file so we don't need to do it
** here.
*/
Valid = MM_WriteFileHeaders(CmdPtr->FileName, FileHandle, &CFEFileHeader,
&MMFileHeader);
Valid = MM_WriteFileHeaders(FileName, FileHandle, &CFEFileHeader, &MMFileHeader);

} /* end MM_ComputeCRCFromFile if */
else
{
Valid = false;
CFE_EVS_SendEvent(MM_COMPUTECRCFROMFILE_ERR_EID, CFE_EVS_EventType_ERROR,
"MM_ComputeCRCFromFile error received: RC = 0x%08X File = '%s'",
(unsigned int)OS_Status, CmdPtr->FileName);
(unsigned int)OS_Status, FileName);
}
}

Expand All @@ -318,12 +321,12 @@ bool MM_DumpMemToFileCmd(const CFE_SB_Buffer_t *BufPtr)
CFE_EVS_SendEvent(
MM_DMP_MEM_FILE_INF_EID, CFE_EVS_EventType_INFORMATION,
"Dump Memory To File Command: Dumped %d bytes from address %p to file '%s'",
(int)MM_AppData.HkPacket.BytesProcessed, (void *)SrcAddress, CmdPtr->FileName);
(int)MM_AppData.HkPacket.BytesProcessed, (void *)SrcAddress, FileName);
/*
** Update last action statistics
*/
MM_AppData.HkPacket.LastAction = MM_DUMP_TO_FILE;
strncpy(MM_AppData.HkPacket.FileName, CmdPtr->FileName, OS_MAX_PATH_LEN);
strncpy(MM_AppData.HkPacket.FileName, FileName, OS_MAX_PATH_LEN);
MM_AppData.HkPacket.MemType = CmdPtr->MemType;
MM_AppData.HkPacket.Address = SrcAddress;
MM_AppData.HkPacket.BytesProcessed = CmdPtr->NumOfBytes;
Expand All @@ -337,16 +340,15 @@ bool MM_DumpMemToFileCmd(const CFE_SB_Buffer_t *BufPtr)
Valid = false;
CFE_EVS_SendEvent(MM_OS_CLOSE_ERR_EID, CFE_EVS_EventType_ERROR,
"OS_close error received: RC = 0x%08X File = '%s'", (unsigned int)OS_Status,
CmdPtr->FileName);
FileName);
}

} /* end OS_OpenCreate if */
else
{
Valid = false;
CFE_EVS_SendEvent(MM_OS_CREAT_ERR_EID, CFE_EVS_EventType_ERROR,
"OS_OpenCreate error received: RC = %d File = '%s'", (int)OS_Status,
CmdPtr->FileName);
"OS_OpenCreate error received: RC = %d File = '%s'", (int)OS_Status, FileName);
}

} /* end MM_VerifyFileLoadDumpParams if */
Expand All @@ -356,7 +358,7 @@ bool MM_DumpMemToFileCmd(const CFE_SB_Buffer_t *BufPtr)
{
Valid = false;
CFE_EVS_SendEvent(MM_SYMNAME_ERR_EID, CFE_EVS_EventType_ERROR,
"Symbolic address can't be resolved: Name = '%s'", CmdPtr->SrcSymAddress.SymName);
"Symbolic address can't be resolved: Name = '%s'", SrcSymAddress.SymName);
}

} /* end MM_VerifyCmdLength if */
Expand Down Expand Up @@ -476,16 +478,17 @@ bool MM_WriteFileHeaders(const char *FileName, osal_id_t FileHandle, CFE_FS_Head
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
bool MM_DumpInEventCmd(const CFE_SB_Buffer_t *BufPtr)
{
bool Valid = false;
MM_DumpInEventCmd_t *CmdPtr;
uint32 i;
int32 EventStringTotalLength = 0;
cpuaddr SrcAddress = 0;
uint16 ExpectedLength = sizeof(MM_DumpInEventCmd_t);
uint8 * BytePtr;
char TempString[MM_DUMPINEVENT_TEMP_CHARS];
const char HeaderString[] = "Memory Dump: ";
static char EventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH];
bool Valid = false;
const MM_DumpInEventCmd_t *CmdPtr;
uint32 i;
int32 EventStringTotalLength = 0;
cpuaddr SrcAddress = 0;
uint16 ExpectedLength = sizeof(MM_DumpInEventCmd_t);
uint8 * BytePtr;
char TempString[MM_DUMPINEVENT_TEMP_CHARS];
const char HeaderString[] = "Memory Dump: ";
static char EventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH];
MM_SymAddr_t SrcSymAddress;

/*
** Allocate a dump buffer. It's declared this way to ensure it stays
Expand All @@ -499,8 +502,10 @@ bool MM_DumpInEventCmd(const CFE_SB_Buffer_t *BufPtr)
{
CmdPtr = ((MM_DumpInEventCmd_t *)BufPtr);

SrcSymAddress = CmdPtr->SrcSymAddress;

/* Resolve the symbolic source address in the command message */
Valid = MM_ResolveSymAddr(&(CmdPtr->SrcSymAddress), &SrcAddress);
Valid = MM_ResolveSymAddr(&(SrcSymAddress), &SrcAddress);

if (Valid == true)
{
Expand Down Expand Up @@ -559,7 +564,7 @@ bool MM_DumpInEventCmd(const CFE_SB_Buffer_t *BufPtr)
else
{
CFE_EVS_SendEvent(MM_SYMNAME_ERR_EID, CFE_EVS_EventType_ERROR,
"Symbolic address can't be resolved: Name = '%s'", CmdPtr->SrcSymAddress.SymName);
"Symbolic address can't be resolved: Name = '%s'", SrcSymAddress.SymName);
}

} /* end MM_VerifyCmdLength if */
Expand Down
Loading

0 comments on commit da7ef70

Please sign in to comment.