Skip to content

Commit

Permalink
Merge pull request #168 from jphickey/fix-123-txfile-cmd-validate
Browse files Browse the repository at this point in the history
Fix #123, validate input params on TxFile and Playback cmds
  • Loading branch information
astrogeco committed Jan 18, 2022
2 parents 1d9719b + ac7a0fb commit 5d55254
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 235 deletions.
28 changes: 28 additions & 0 deletions fsw/src/cf_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,20 @@ void CF_CmdTxFile(CFE_SB_Buffer_t *msg)
{
CF_TxFileCmd_t *tx = (CF_TxFileCmd_t *)msg;

/*
* This needs to validate all its inputs.
* "keep" should only be 0 or 1 (logical true/false).
* For priority and dest_id params, anything is acceptable.
*/
if (tx->cfdp_class > CF_CFDP_CLASS_2 || tx->chan_num >= CF_NUM_CHANNELS || tx->keep > 1)
{
CFE_EVS_SendEvent(CF_EID_ERR_CMD_BAD_PARAM, CFE_EVS_EventType_ERROR,
"CF: bad parameter in CF_CmdTxFile(): chan=%u, class=%u keep=%u", (unsigned int)tx->chan_num,
(unsigned int)tx->cfdp_class, (unsigned int)tx->keep);
CF_CmdRej();
return;
}

/* make sure that the src and dst filenames are null terminated */
tx->src_filename[sizeof(tx->src_filename) - 1] = 0;
tx->dst_filename[sizeof(tx->dst_filename) - 1] = 0;
Expand All @@ -162,6 +176,20 @@ void CF_CmdPlaybackDir(CFE_SB_Buffer_t *msg)
{
CF_PlaybackDirCmd_t *tx = (CF_PlaybackDirCmd_t *)msg;

/*
* This needs to validate all its inputs.
* "keep" should only be 0 or 1 (logical true/false).
* For priority and dest_id params, anything is acceptable.
*/
if (tx->cfdp_class > CF_CFDP_CLASS_2 || tx->chan_num >= CF_NUM_CHANNELS || tx->keep > 1)
{
CFE_EVS_SendEvent(CF_EID_ERR_CMD_BAD_PARAM, CFE_EVS_EventType_ERROR,
"CF: bad parameter in CF_CmdPlaybackDir(): chan=%u, class=%u keep=%u",
(unsigned int)tx->chan_num, (unsigned int)tx->cfdp_class, (unsigned int)tx->keep);
CF_CmdRej();
return;
}

/* make sure that the src and dst filenames are null terminated */
tx->src_filename[sizeof(tx->src_filename) - 1] = 0;
tx->dst_filename[sizeof(tx->dst_filename) - 1] = 0;
Expand Down
1 change: 1 addition & 0 deletions fsw/src/cf_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,6 @@
#define CF_EID_ERR_CMD_GCMD_LEN 136
#define CF_EID_ERR_CMD_GCMD_CC 137
#define CF_EID_ERR_CMD_WHIST_WRITE 138
#define CF_EID_ERR_CMD_BAD_PARAM 139

#endif /* !CF_EVENTS_H */
Loading

0 comments on commit 5d55254

Please sign in to comment.