Skip to content

Commit

Permalink
Fix nasa#127, Adds static analysis comments and replaces strncpy with…
Browse files Browse the repository at this point in the history
… snprintf

This commit addresses issues flagged during static analysis by:
- Adding JSC 2.1 disposition comments.
- Replacing strncpy with snprintf to enhance safety and compliance.
- Changes DS_TABLE_VERIFY_ERR from 0xFFFFFFFF to -1
  • Loading branch information
jdfiguer authored and jdfiguer committed Jun 14, 2024
1 parent 3c93bc7 commit 74cb926
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 6 deletions.
3 changes: 1 addition & 2 deletions fsw/src/ds_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,7 @@ void DS_AppSendHkCmd(void)
Status = CFE_TBL_GetInfo(&FilterTblInfo, FilterTblName);
if (Status == CFE_SUCCESS)
{
strncpy(PayloadPtr->FilterTblFilename, FilterTblInfo.LastFileLoaded, OS_MAX_PATH_LEN - 1);
PayloadPtr->FilterTblFilename[OS_MAX_PATH_LEN - 1] = '\0';
snprintf(PayloadPtr->FilterTblFilename, OS_MAX_PATH_LEN, "%s", FilterTblInfo.LastFileLoaded);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion fsw/src/ds_appdefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

#define DS_PATH_SEPARATOR '/' /**< \brief File system path separator */

#define DS_TABLE_VERIFY_ERR 0xFFFFFFFF /**< \brief Table verification error return value */
#define DS_TABLE_VERIFY_ERR -1 /**< \brief Table verification error return value */

#define DS_FILE_HEADER_NONE 0 /**< \brief File header type is NONE */
#define DS_FILE_HEADER_CFE 1 /**< \brief File header type is CFE */
Expand Down
2 changes: 1 addition & 1 deletion fsw/src/ds_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,7 @@ void DS_GetFileInfoCmd(const CFE_SB_Buffer_t *BufPtr)
/*
** Set current open filename...
*/
strncpy(FileInfoPtr->FileName, DS_AppData.FileStatus[i].FileName, sizeof(FileInfoPtr->FileName));
snprintf(FileInfoPtr->FileName, sizeof(FileInfoPtr->FileName), "%s", DS_AppData.FileStatus[i].FileName);
}
}

Expand Down
4 changes: 2 additions & 2 deletions fsw/src/ds_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ void DS_FileCloseDest(int32 FileIndex)
}

/* Update the path name for reporting */
strncpy(FileStatus->FileName, PathName, sizeof(FileStatus->FileName));
snprintf(FileStatus->FileName, sizeof(FileStatus->FileName), "%s", PathName);
}
#else
/*
Expand Down Expand Up @@ -998,7 +998,7 @@ void DS_FileTransmit(DS_AppFileStatus_t *FileStatus)
/*
** Set current open filename...
*/
strncpy(FileInfo->FileName, FileStatus->FileName, sizeof(FileInfo->FileName));
snprintf(FileInfo->FileName, sizeof(FileInfo->FileName), "%s", FileStatus->FileName);

/*
** Timestamp and send file info telemetry...
Expand Down
2 changes: 2 additions & 0 deletions fsw/src/ds_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ CFE_Status_t DS_TableVerifyDestFile(const void *TableData)
else
{
CountBad++;
/* SAD: Assignment of 0xFFFFFFFF to Result is safe; it represents -1 in int32, within valid range */
Result = DS_TABLE_VERIFY_ERR;
}
}
Expand Down Expand Up @@ -542,6 +543,7 @@ CFE_Status_t DS_TableVerifyFilter(const void *TableData)
else
{
CountBad++;
/* SAD: Assignment of 0xFFFFFFFF to Result is safe; it represents -1 in int32, within valid range */
Result = DS_TABLE_VERIFY_ERR;
}
}
Expand Down

0 comments on commit 74cb926

Please sign in to comment.