Skip to content

Commit

Permalink
Merge pull request nasa#46 from CDKnightNASA/fix-45-term_filenames
Browse files Browse the repository at this point in the history
Fix nasa#45 - null terminates src/dst filenames
  • Loading branch information
astrogeco authored Jul 1, 2020
2 parents 9b83687 + 655c0d4 commit 685964d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions elf2cfetbl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1227,11 +1227,13 @@ int32 ProcessCmdLineOptions(int ArgumentCount, char *Arguments[])
else if (!InputFileSpecified)
{
strncpy(SrcFilename, Arguments[i], PATH_MAX - 1);
SrcFilename[PATH_MAX - 1] = '\0';
InputFileSpecified = true;
}
else if (!OutputFileSpecified)
{
strncpy(DstFilename, Arguments[i], PATH_MAX - 1);
DstFilename[PATH_MAX - 1] = '\0';
OutputFileSpecified = true;
}
else
Expand Down Expand Up @@ -2247,6 +2249,12 @@ int32 GetTblDefInfo(void)
fseek(SrcFileDesc, SeekOffset, SEEK_SET);
NumDefsRead = fread(&TblFileDef, sizeof(CFE_TBL_FileDef_t), 1, SrcFileDesc);

/* ensuring all are strings are null-terminated */
TblFileDef.ObjectName[sizeof(TblFileDef.ObjectName) - 1] = '\0';
TblFileDef.TableName[sizeof(TblFileDef.TableName) - 1] = '\0';
TblFileDef.Description[sizeof(TblFileDef.Description) - 1] = '\0';
TblFileDef.TgtFilename[sizeof(TblFileDef.TgtFilename) - 1] = '\0';

if (NumDefsRead != 1)
{
printf("Error! Unable to read data content of '%s' from '%s'.\n", TBL_DEF_SYMBOL_NAME, SrcFilename);
Expand Down

0 comments on commit 685964d

Please sign in to comment.