Skip to content

Commit

Permalink
Fix #117, Replaces strncpy with snprintf
Browse files Browse the repository at this point in the history
  • Loading branch information
jdfiguer authored and jdfiguer committed Jun 14, 2024
1 parent f033752 commit 8157a4d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
9 changes: 3 additions & 6 deletions fsw/src/fm_child.c
Original file line number Diff line number Diff line change
Expand Up @@ -801,8 +801,7 @@ void FM_ChildFileInfoCmd(FM_ChildQueueEntry_t *CmdArgs)

/* Report directory or filename state, name, size and time */
ReportPtr->FileStatus = (uint8)CmdArgs->FileInfoState;
strncpy(ReportPtr->Filename, CmdArgs->Source1, OS_MAX_PATH_LEN - 1);
ReportPtr->Filename[OS_MAX_PATH_LEN - 1] = '\0';
snprintf(ReportPtr->Filename, OS_MAX_PATH_LEN, "%s", CmdArgs->Source1);

ReportPtr->FileSize = CmdArgs->FileInfoSize;
ReportPtr->LastModifiedTime = CmdArgs->FileInfoTime;
Expand Down Expand Up @@ -1157,8 +1156,7 @@ void FM_ChildDirListPktCmd(const FM_ChildQueueEntry_t *CmdArgs)

ReportPtr = &FM_GlobalData.DirListPkt.Payload;

strncpy(ReportPtr->DirName, CmdArgs->Source1, OS_MAX_PATH_LEN - 1);
ReportPtr->DirName[OS_MAX_PATH_LEN - 1] = '\0';
snprintf(ReportPtr->DirName, OS_MAX_PATH_LEN, "%s", CmdArgs->Source1);
ReportPtr->FirstFile = CmdArgs->DirListOffset;

StillProcessing = true;
Expand Down Expand Up @@ -1193,8 +1191,7 @@ void FM_ChildDirListPktCmd(const FM_ChildQueueEntry_t *CmdArgs)
if ((PathLength + EntryLength) < sizeof(LogicalName))
{
/* Add filename to directory listing telemetry packet */
strncpy(ListEntry->EntryName, OS_DIRENTRY_NAME(DirEntry), sizeof(ListEntry->EntryName) - 1);
ListEntry->EntryName[sizeof(ListEntry->EntryName) - 1] = '\0';
snprintf(ListEntry->EntryName, sizeof(ListEntry->EntryName), "%s", OS_DIRENTRY_NAME(DirEntry));

/* Build filename - Directory already has path separator */
memcpy(LogicalName, CmdArgs->Source2, PathLength);
Expand Down
5 changes: 2 additions & 3 deletions fsw/src/fm_cmd_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -577,8 +577,7 @@ CFE_Status_t FM_GetDirectorySpaceEstimate(const char *Directory, uint64 *BlockCo
TotalBytes = 0;

memset(&DirEntry, 0, sizeof(DirEntry));
strncpy(FullPath, Directory, sizeof(FullPath) - 1);
FullPath[sizeof(FullPath) - 1] = 0;
snprintf(FullPath, sizeof(FullPath), "%s", Directory);
DirLen = strlen(FullPath);
if (DirLen < (sizeof(FullPath) - 2))
{
Expand Down Expand Up @@ -607,7 +606,7 @@ CFE_Status_t FM_GetDirectorySpaceEstimate(const char *Directory, uint64 *BlockCo
/* Read each directory entry and stat the files */
while (OS_DirectoryRead(DirId, &DirEntry) == OS_SUCCESS)
{
strncpy(&FullPath[DirLen], OS_DIRENTRY_NAME(DirEntry), sizeof(FullPath) - DirLen - 1);
snprintf(&FullPath[DirLen], sizeof(FullPath) - DirLen, "%s", OS_DIRENTRY_NAME(DirEntry));

OS_Status = OS_stat(FullPath, &FileStat);
if (OS_Status != OS_SUCCESS)
Expand Down
6 changes: 2 additions & 4 deletions fsw/src/fm_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,8 @@ bool FM_DecompressFileCmd(const CFE_SB_Buffer_t *BufPtr)

/* Set handshake queue command args */
CmdArgs->CommandCode = FM_DECOMPRESS_FILE_CC;
strncpy(CmdArgs->Source1, CmdPtr->Source, OS_MAX_PATH_LEN - 1);
CmdArgs->Source1[OS_MAX_PATH_LEN - 1] = '\0';
strncpy(CmdArgs->Target, CmdPtr->Target, OS_MAX_PATH_LEN - 1);
CmdArgs->Target[OS_MAX_PATH_LEN - 1] = '\0';
snprintf(CmdArgs->Source1, OS_MAX_PATH_LEN, "%s", CmdPtr->Source);
snprintf(CmdArgs->Target, OS_MAX_PATH_LEN, "%s", CmdPtr->Target);

/* Invoke lower priority child task */
FM_InvokeChildTask();
Expand Down

0 comments on commit 8157a4d

Please sign in to comment.