Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/msg/fsw/src/cfe_msg_ccsdsext.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ CFE_Status_t CFE_MSG_GetSystem(const CFE_MSG_Message_t *MsgPtr, CFE_MSG_System_t
return CFE_MSG_BAD_ARGUMENT;
}

*System = (MsgPtr->CCSDS.Ext.SystemId[0] << 8) + MsgPtr->CCSDS.Ext.SystemId[1];
*System = ((uint16)MsgPtr->CCSDS.Ext.SystemId[0] << 8) | MsgPtr->CCSDS.Ext.SystemId[1];

return CFE_SUCCESS;
}
Expand Down
5 changes: 2 additions & 3 deletions modules/msg/fsw/src/cfe_msg_ccsdspri.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@

#include <assert.h>

/* CCSDS Primary Standard definitions */
#define CFE_MSG_SIZE_OFFSET 7 /**< \brief CCSDS size offset */
/* CCSDS Primary Standard definitions (CFE_MSG_SIZE_OFFSET is in cfe_msg_priv.h) */
#define CFE_MSG_CCSDSVER_MASK 0xE000 /**< \brief CCSDS version mask */
#define CFE_MSG_CCSDSVER_SHIFT 13 /**< \brief CCSDS version shift */
#define CFE_MSG_TYPE_MASK 0x1000 /**< \brief CCSDS type mask, command when set */
Expand Down Expand Up @@ -378,7 +377,7 @@ CFE_Status_t CFE_MSG_GetSize(const CFE_MSG_Message_t *MsgPtr, CFE_MSG_Size_t *Si
return CFE_MSG_BAD_ARGUMENT;
}

*Size = (MsgPtr->CCSDS.Pri.Length[0] << 8) + MsgPtr->CCSDS.Pri.Length[1] + CFE_MSG_SIZE_OFFSET;
*Size = (((uint16)MsgPtr->CCSDS.Pri.Length[0] << 8) | MsgPtr->CCSDS.Pri.Length[1]) + CFE_MSG_SIZE_OFFSET;

return CFE_SUCCESS;
}
Expand Down
7 changes: 7 additions & 0 deletions modules/msg/fsw/src/cfe_msg_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ CFE_Status_t CFE_MSG_Init(CFE_MSG_Message_t *MsgPtr, CFE_SB_MsgId_t MsgId, CFE_M
return CFE_MSG_BAD_ARGUMENT;
}

/* Reject an invalid size before it is used as the memset length. CFE_MSG_SetSize
* enforces the same bounds, but only after the buffer has already been cleared */
if (Size < CFE_MSG_SIZE_OFFSET || Size > (0xFFFF + CFE_MSG_SIZE_OFFSET))
{
return CFE_MSG_BAD_ARGUMENT;
}

/* Clear and set defaults */
memset(MsgPtr, 0, Size);
CFE_MSG_InitDefaultHdr(MsgPtr);
Expand Down
3 changes: 3 additions & 0 deletions modules/msg/fsw/src/cfe_msg_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
#include "common_types.h"
#include "cfe_msg_hdr.h"

/* CCSDS size offset, shared by the size accessors and CFE_MSG_Init */
#define CFE_MSG_SIZE_OFFSET 7 /**< \brief CCSDS size offset */

/*---------------------------------------------------------------------------------------*/
/**
* \brief get generic header field (uint8 array[2])
Expand Down
16 changes: 16 additions & 0 deletions modules/msg/ut-coverage/test_cfe_msg_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "test_cfe_msg_init.h"
#include "cfe_error.h"
#include "cfe_msg_defaults.h"
#include "cfe_msg_priv.h"
#include <string.h>

#define TEST_DEFAULT_APID_MASK 0x780 /* Bits that can be set by default apid if msgid V2 */
Expand All @@ -40,6 +41,12 @@
*/
void Test_MSG_Init(void)
{
/* Sized to the largest length CFE_MSG_SetSize accepts; static to keep it off the stack */
static union
{
CFE_MSG_Message_t Msg;
uint8 Bytes[0xFFFF + CFE_MSG_SIZE_OFFSET];
} maxmsg;
CFE_MSG_CommandHeader_t cmd;
CFE_MSG_Size_t size;
CFE_SB_MsgId_Atom_t msgidval_exp;
Expand All @@ -57,6 +64,15 @@ void Test_MSG_Init(void)
UT_SetDefaultReturnValue(UT_KEY(CFE_SB_IsValidMsgId), true);
UtAssert_INT32_EQ(CFE_MSG_Init(NULL, msgid_act, sizeof(cmd)), CFE_MSG_BAD_ARGUMENT);
UtAssert_INT32_EQ(CFE_MSG_Init(CFE_MSG_PTR(cmd), msgid_act, 0), CFE_MSG_BAD_ARGUMENT);
UtAssert_INT32_EQ(CFE_MSG_Init(CFE_MSG_PTR(cmd), msgid_act, CFE_MSG_SIZE_OFFSET - 1), CFE_MSG_BAD_ARGUMENT);

/* An oversize length must be rejected before it is used to clear the buffer: cmd is only a
* command header, so clearing 0xFFFF + CFE_MSG_SIZE_OFFSET + 1 bytes would run past it */
UtAssert_INT32_EQ(CFE_MSG_Init(CFE_MSG_PTR(cmd), msgid_act, 0xFFFF + CFE_MSG_SIZE_OFFSET + 1),
CFE_MSG_BAD_ARGUMENT);

/* The largest representable size is still accepted */
CFE_UtAssert_SUCCESS(CFE_MSG_Init(&maxmsg.Msg, msgid_act, sizeof(maxmsg)));
UT_SetDefaultReturnValue(UT_KEY(CFE_SB_IsValidMsgId), false);
UtAssert_INT32_EQ(CFE_MSG_Init(CFE_MSG_PTR(cmd), msgid_act, sizeof(cmd)), CFE_MSG_BAD_ARGUMENT);
UtAssert_INT32_EQ(CFE_MSG_Init(CFE_MSG_PTR(cmd), CFE_SB_INVALID_MSG_ID, sizeof(cmd)), CFE_SUCCESS);
Expand Down