Skip to content

Commit

Permalink
Fix #123, validate input params on TxFile and Playback cmds
Browse files Browse the repository at this point in the history
The input parameters on TxFile and Playback commands was not being
sufficiently validated before calling the internal routine.
  • Loading branch information
jphickey committed Jan 12, 2022
1 parent c0bf0bd commit ac7a0fb
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 ac7a0fb

Please sign in to comment.