From eae96f5c907d0057c57cdad8ad53c0549c376633 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Tue, 19 Dec 2023 14:09:16 -0500 Subject: [PATCH] Fix #2488, separate bad argument test Pass in CFE_SB_INVALID_MSG_ID separately from a NULL pointer. This also required updates to the way the MSG module checks the MsgID, as it was not using the IsValidMsgID check. --- modules/cfe_testcase/src/msg_api_test.c | 6 ++++-- modules/msg/fsw/src/cfe_msg_msgid_v1.c | 2 +- modules/msg/fsw/src/cfe_msg_msgid_v2.c | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/modules/cfe_testcase/src/msg_api_test.c b/modules/cfe_testcase/src/msg_api_test.c index 623e60973..6f3addb0a 100644 --- a/modules/cfe_testcase/src/msg_api_test.c +++ b/modules/cfe_testcase/src/msg_api_test.c @@ -26,6 +26,7 @@ */ #include "cfe_test.h" +#include "cfe_test_msgids.h" #include void TestMsgApiBasic(void) @@ -49,7 +50,8 @@ void TestMsgApiBasic(void) msgId = CFE_SB_ValueToMsgId(1); /* test msg-init */ - UtAssert_INT32_EQ(CFE_MSG_Init(NULL, CFE_SB_INVALID_MSG_ID, sizeof(cmd)), CFE_MSG_BAD_ARGUMENT); + UtAssert_INT32_EQ(CFE_MSG_Init(NULL, msgId, sizeof(cmd)), CFE_MSG_BAD_ARGUMENT); + UtAssert_INT32_EQ(CFE_MSG_Init(CFE_MSG_PTR(cmd), CFE_SB_INVALID_MSG_ID, sizeof(cmd)), CFE_MSG_BAD_ARGUMENT); UtAssert_INT32_EQ(CFE_MSG_Init(CFE_MSG_PTR(cmd), msgId, 0), CFE_MSG_BAD_ARGUMENT); UtAssert_INT32_EQ( CFE_MSG_Init(CFE_MSG_PTR(cmd), CFE_SB_ValueToMsgId(CFE_PLATFORM_SB_HIGHEST_VALID_MSGID + 1), sizeof(cmd)), @@ -135,7 +137,7 @@ void TestMsgApiAdvanced(void) CFE_MSG_SequenceCount_t seqCnt; memset(&cmd, 0xFF, sizeof(cmd)); - msgId = CFE_SB_INVALID_MSG_ID; + msgId = CFE_SB_ValueToMsgId(CFE_TEST_CMD_MID); UtAssert_INT32_EQ(CFE_MSG_Init(CFE_MSG_PTR(cmd), msgId, sizeof(cmd)), CFE_SUCCESS); diff --git a/modules/msg/fsw/src/cfe_msg_msgid_v1.c b/modules/msg/fsw/src/cfe_msg_msgid_v1.c index e4574e2fe..b205f18ac 100644 --- a/modules/msg/fsw/src/cfe_msg_msgid_v1.c +++ b/modules/msg/fsw/src/cfe_msg_msgid_v1.c @@ -56,7 +56,7 @@ CFE_Status_t CFE_MSG_SetMsgId(CFE_MSG_Message_t *MsgPtr, CFE_SB_MsgId_t MsgId) { CFE_SB_MsgId_Atom_t msgidval = CFE_SB_MsgIdToValue(MsgId); - if (MsgPtr == NULL || msgidval > CFE_PLATFORM_SB_HIGHEST_VALID_MSGID) + if (MsgPtr == NULL || !CFE_SB_IsValidMsgId(MsgId)) { return CFE_MSG_BAD_ARGUMENT; } diff --git a/modules/msg/fsw/src/cfe_msg_msgid_v2.c b/modules/msg/fsw/src/cfe_msg_msgid_v2.c index 8c8876fae..f402a729d 100644 --- a/modules/msg/fsw/src/cfe_msg_msgid_v2.c +++ b/modules/msg/fsw/src/cfe_msg_msgid_v2.c @@ -88,7 +88,7 @@ CFE_Status_t CFE_MSG_SetMsgId(CFE_MSG_Message_t *MsgPtr, CFE_SB_MsgId_t MsgId) { CFE_SB_MsgId_Atom_t msgidval = CFE_SB_MsgIdToValue(MsgId); - if (MsgPtr == NULL || msgidval > CFE_PLATFORM_SB_HIGHEST_VALID_MSGID) + if (MsgPtr == NULL || !CFE_SB_IsValidMsgId(MsgId)) { return CFE_MSG_BAD_ARGUMENT; }