From 5716b953db1056a274bebc9a8b9265a3dc1ac6ee Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Thu, 16 Sep 2021 13:50:16 -0400 Subject: [PATCH] Fix #1952, patch for recursive event loop Adds CFE_SB_RequestToSendEvent/CFE_SB_FinishSendEvent wrappers around all events generated by CFE_SB_TransmitMsgValidate. This is avoids the potential for a recursive loop if configured improperly. --- modules/sb/fsw/src/cfe_sb_api.c | 42 +++++++++++++++++++++++--------- modules/sb/fsw/src/cfe_sb_priv.h | 14 ++++++----- 2 files changed, 38 insertions(+), 18 deletions(-) diff --git a/modules/sb/fsw/src/cfe_sb_api.c b/modules/sb/fsw/src/cfe_sb_api.c index fb5f119be..66bd02845 100644 --- a/modules/sb/fsw/src/cfe_sb_api.c +++ b/modules/sb/fsw/src/cfe_sb_api.c @@ -1503,24 +1503,42 @@ int32 CFE_SB_TransmitMsgValidate(const CFE_MSG_Message_t *MsgPtr, CFE_SB_MsgId_t switch (PendingEventID) { case CFE_SB_SEND_BAD_ARG_EID: - CFE_EVS_SendEventWithAppID(CFE_SB_SEND_BAD_ARG_EID, CFE_EVS_EventType_ERROR, CFE_SB_Global.AppId, - "Send Err:Bad input argument,Arg 0x%lx,App %s", (unsigned long)MsgPtr, - CFE_SB_GetAppTskName(TskId, FullName)); + if (CFE_SB_RequestToSendEvent(TskId, CFE_SB_SEND_BAD_ARG_EID_BIT) == CFE_SB_GRANTED) + { + CFE_EVS_SendEventWithAppID(CFE_SB_SEND_BAD_ARG_EID, CFE_EVS_EventType_ERROR, CFE_SB_Global.AppId, + "Send Err:Bad input argument,Arg 0x%lx,App %s", (unsigned long)MsgPtr, + CFE_SB_GetAppTskName(TskId, FullName)); + + /* clear the bit so the task may send this event again */ + CFE_SB_FinishSendEvent(TskId, CFE_SB_SEND_BAD_ARG_EID_BIT); + } break; case CFE_SB_SEND_INV_MSGID_EID: - CFE_EVS_SendEventWithAppID(CFE_SB_SEND_INV_MSGID_EID, CFE_EVS_EventType_ERROR, CFE_SB_Global.AppId, - "Send Err:Invalid MsgId(0x%x)in msg,App %s", - (unsigned int)CFE_SB_MsgIdToValue(*MsgIdPtr), - CFE_SB_GetAppTskName(TskId, FullName)); + if (CFE_SB_RequestToSendEvent(TskId, CFE_SB_SEND_INV_MSGID_EID_BIT) == CFE_SB_GRANTED) + { + CFE_EVS_SendEventWithAppID(CFE_SB_SEND_INV_MSGID_EID, CFE_EVS_EventType_ERROR, CFE_SB_Global.AppId, + "Send Err:Invalid MsgId(0x%x)in msg,App %s", + (unsigned int)CFE_SB_MsgIdToValue(*MsgIdPtr), + CFE_SB_GetAppTskName(TskId, FullName)); + + /* clear the bit so the task may send this event again */ + CFE_SB_FinishSendEvent(TskId, CFE_SB_SEND_INV_MSGID_EID_BIT); + } break; case CFE_SB_MSG_TOO_BIG_EID: - CFE_EVS_SendEventWithAppID(CFE_SB_MSG_TOO_BIG_EID, CFE_EVS_EventType_ERROR, CFE_SB_Global.AppId, - "Send Err:Msg Too Big MsgId=0x%x,app=%s,size=%d,MaxSz=%d", - (unsigned int)CFE_SB_MsgIdToValue(*MsgIdPtr), - CFE_SB_GetAppTskName(TskId, FullName), (int)*SizePtr, - CFE_MISSION_SB_MAX_SB_MSG_SIZE); + if (CFE_SB_RequestToSendEvent(TskId, CFE_SB_MSG_TOO_BIG_EID_BIT) == CFE_SB_GRANTED) + { + CFE_EVS_SendEventWithAppID(CFE_SB_MSG_TOO_BIG_EID, CFE_EVS_EventType_ERROR, CFE_SB_Global.AppId, + "Send Err:Msg Too Big MsgId=0x%x,app=%s,size=%d,MaxSz=%d", + (unsigned int)CFE_SB_MsgIdToValue(*MsgIdPtr), + CFE_SB_GetAppTskName(TskId, FullName), (int)*SizePtr, + CFE_MISSION_SB_MAX_SB_MSG_SIZE); + + /* clear the bit so the task may send this event again */ + CFE_SB_FinishSendEvent(TskId, CFE_SB_MSG_TOO_BIG_EID_BIT); + } break; case CFE_SB_SEND_NO_SUBS_EID: diff --git a/modules/sb/fsw/src/cfe_sb_priv.h b/modules/sb/fsw/src/cfe_sb_priv.h index 54df50a38..1e781f83e 100644 --- a/modules/sb/fsw/src/cfe_sb_priv.h +++ b/modules/sb/fsw/src/cfe_sb_priv.h @@ -90,12 +90,14 @@ #define CFE_SB_FILE_IO_ERR (-5) /* bit map for stopping recursive event problem */ -#define CFE_SB_SEND_NO_SUBS_EID_BIT 0 -#define CFE_SB_GET_BUF_ERR_EID_BIT 1 -#define CFE_SB_MSGID_LIM_ERR_EID_BIT 2 -#define CFE_SB_Q_FULL_ERR_EID_BIT 3 -#define CFE_SB_Q_WR_ERR_EID_BIT 4 - +#define CFE_SB_SEND_NO_SUBS_EID_BIT 0 +#define CFE_SB_GET_BUF_ERR_EID_BIT 1 +#define CFE_SB_MSGID_LIM_ERR_EID_BIT 2 +#define CFE_SB_Q_FULL_ERR_EID_BIT 3 +#define CFE_SB_Q_WR_ERR_EID_BIT 4 +#define CFE_SB_SEND_BAD_ARG_EID_BIT 5 +#define CFE_SB_SEND_INV_MSGID_EID_BIT 6 +#define CFE_SB_MSG_TOO_BIG_EID_BIT 7 /* ** Type Definitions */