From 82dc53307e392e659d4fa9bc44bcd1fdbc11a6cb Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Thu, 13 Jan 2022 16:43:44 -0500 Subject: [PATCH] Fix #95, reject PDUs with large bit set This bit indicates that the PDU has 64-bit size and offset fields. CF currently does not support large file sizes. It needs to reject these packets as they will corrupt the data because they are not decoded properly (decode is fixed at 32 bit sizes). --- fsw/src/cf_cfdp.c | 13 +++++++++++++ fsw/src/cf_events.h | 1 + fsw/tables/cf_def_config.c | 4 ++-- unit-test/cf_cfdp_tests.c | 6 ++++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/fsw/src/cf_cfdp.c b/fsw/src/cf_cfdp.c index bbdebfb0..fc068d7e 100644 --- a/fsw/src/cf_cfdp.c +++ b/fsw/src/cf_cfdp.c @@ -632,6 +632,19 @@ int CF_CFDP_RecvPh(uint8 chan_num, CF_Logical_PduBuffer_t *ph) CF_CFDP_DecodeHeader(ph->pdec, &ph->pdu_header); + /* + * The "large file" flag is not supported by this implementation yet. + * This means file sizes and offsets will be 64 bits, so codec routines + * will need to be updated to understand this. OSAL also doesn't support + * 64-bit file access yet. + */ + if (CF_CODEC_IS_OK(ph->pdec) && ph->pdu_header.large_flag) + { + CFE_EVS_SendEvent(CF_EID_ERR_PDU_LARGE_FILE, CFE_EVS_EventType_ERROR, + "CF: pdu with large file bit received (unsupported)"); + goto err_out; + } + if (CF_CODEC_IS_OK(ph->pdec) && ph->pdu_header.pdu_type == 0) { CF_CFDP_DecodeFileDirectiveHeader(ph->pdec, &ph->fdirective); diff --git a/fsw/src/cf_events.h b/fsw/src/cf_events.h index 11c20bea..bbf083d0 100644 --- a/fsw/src/cf_events.h +++ b/fsw/src/cf_events.h @@ -64,6 +64,7 @@ #define CF_EID_ERR_PDU_GET_EID_SIZE 52 #define CF_EID_ERR_PDU_GET_TSN_SIZE 53 #define CF_EID_ERR_PDU_FD_UNSUPPORTED 54 +#define CF_EID_ERR_PDU_LARGE_FILE 55 /* CF_CFDP event ids (engine) */ #define CF_EID_ERR_CFDP_RX_DROPPED 60 diff --git a/fsw/tables/cf_def_config.c b/fsw/tables/cf_def_config.c index 5590455f..264b70aa 100644 --- a/fsw/tables/cf_def_config.c +++ b/fsw/tables/cf_def_config.c @@ -39,7 +39,7 @@ CF_ConfigTable_t CF_config_table = { 0x08c2, 16, {{5, 25, CF_CFDP_CLASS_2, 23, "/cf/poll_dir", "./poll_dir", 0}, {0}, {0}, {0}, {0}}, - "cf_1_sem", + "", /* throttle sem for channel 1, empty string means no throttle */ 1, }, {5, /* max number of outgoing messages per wakeup */ @@ -48,7 +48,7 @@ CF_ConfigTable_t CF_config_table = { 0x08c3, 16, {{0}, {0}, {0}, {0}, {0}}, - "cf_2_sem", + "", /* throttle sem for channel 2, empty string means no throttle */ 1}}, 3, /* ack timer */ 3, /* nak timer */ diff --git a/unit-test/cf_cfdp_tests.c b/unit-test/cf_cfdp_tests.c index 60e2d434..8039f4d3 100644 --- a/unit-test/cf_cfdp_tests.c +++ b/unit-test/cf_cfdp_tests.c @@ -255,6 +255,12 @@ void Test_CF_CFDP_RecvPh(void) CF_CODEC_SET_DONE(ph->pdec); UtAssert_INT32_EQ(CF_CFDP_RecvPh(UT_CFDP_CHANNEL, ph), -1); UT_CF_AssertEventID(CF_EID_ERR_PDU_SHORT_HEADER); + + /* decode error, large file bit set */ + UT_CFDP_SetupBasicTestState(UT_CF_Setup_RX, &ph, NULL, NULL, NULL, NULL); + ph->pdu_header.large_flag = true; + UtAssert_INT32_EQ(CF_CFDP_RecvPh(UT_CFDP_CHANNEL, ph), -1); + UT_CF_AssertEventID(CF_EID_ERR_PDU_LARGE_FILE); } void Test_CF_CFDP_RecvMd(void)