From f1918c64e6e11687b58f6709dc483c1cfba18bf0 Mon Sep 17 00:00:00 2001 From: jdfiguer Date: Wed, 6 Sep 2023 14:54:04 -0400 Subject: [PATCH] Fix #2436, Adds an empty string or null pointer check for pipe creation --- modules/cfe_testcase/src/sb_pipe_mang_test.c | 1 + modules/sb/fsw/src/cfe_sb_api.c | 2 +- modules/sb/ut-coverage/sb_UT.c | 31 ++++++++++++++++++++ modules/sb/ut-coverage/sb_UT.h | 15 ++++++++++ 4 files changed, 48 insertions(+), 1 deletion(-) diff --git a/modules/cfe_testcase/src/sb_pipe_mang_test.c b/modules/cfe_testcase/src/sb_pipe_mang_test.c index 431ac8eed..0fe7b5f2c 100644 --- a/modules/cfe_testcase/src/sb_pipe_mang_test.c +++ b/modules/cfe_testcase/src/sb_pipe_mang_test.c @@ -47,6 +47,7 @@ void TestPipeCreate(void) UtAssert_INT32_EQ(CFE_SB_CreatePipe(&PipeId1, OS_QUEUE_MAX_DEPTH + 5, PipeName), CFE_SB_BAD_ARGUMENT); UtAssert_INT32_EQ(CFE_SB_CreatePipe(&PipeId1, 0, PipeName), CFE_SB_BAD_ARGUMENT); UtAssert_INT32_EQ(CFE_SB_CreatePipe(&PipeId1, PipeDepth, NULL), CFE_SB_PIPE_CR_ERR); + UtAssert_INT32_EQ(CFE_SB_CreatePipe(&PipeId1, PipeDepth, ""), CFE_SB_BAD_ARGUMENT); } void TestPipeCreateMax(void) diff --git a/modules/sb/fsw/src/cfe_sb_api.c b/modules/sb/fsw/src/cfe_sb_api.c index 1b9574260..b4747f452 100644 --- a/modules/sb/fsw/src/cfe_sb_api.c +++ b/modules/sb/fsw/src/cfe_sb_api.c @@ -123,7 +123,7 @@ CFE_Status_t CFE_SB_CreatePipe(CFE_SB_PipeId_t *PipeIdPtr, uint16 Depth, const c CFE_ES_GetTaskID(&TskId); /* check input parameters */ - if ((PipeIdPtr == NULL) || (Depth > OS_QUEUE_MAX_DEPTH) || (Depth == 0)) + if ((PipeIdPtr == NULL) || (Depth > OS_QUEUE_MAX_DEPTH) || (Depth == 0) || (PipeName != NULL && PipeName[0] == '\0')) { PendingEventId = CFE_SB_CR_PIPE_BAD_ARG_EID; Status = CFE_SB_BAD_ARGUMENT; diff --git a/modules/sb/ut-coverage/sb_UT.c b/modules/sb/ut-coverage/sb_UT.c index 78c89bab5..8ed24cf79 100644 --- a/modules/sb/ut-coverage/sb_UT.c +++ b/modules/sb/ut-coverage/sb_UT.c @@ -1645,6 +1645,8 @@ void Test_CreatePipe_API(void) SB_UT_ADD_SUBTEST(Test_CreatePipe_InvalPipeDepth); SB_UT_ADD_SUBTEST(Test_CreatePipe_MaxPipes); SB_UT_ADD_SUBTEST(Test_CreatePipe_SamePipeName); + SB_UT_ADD_SUBTEST(Test_CreatePipe_EmptyPipeName); + SB_UT_ADD_SUBTEST(Test_CreatePipe_PipeName_NullPtr); } /* @@ -1798,6 +1800,35 @@ void Test_CreatePipe_SamePipeName(void) CFE_UtAssert_TEARDOWN(CFE_SB_DeletePipe(PipeId)); } +/* +** Test create pipe response to empty pipe name +*/ +void Test_CreatePipe_EmptyPipeName(void) +{ + CFE_SB_PipeId_t PipeId = SB_UT_PIPEID_0; + uint16 PipeDepth = 1; + char PipeName[] = ""; + + /* Call to CFE_SB_CreatePipe with empty PipeName should fail */ + UtAssert_INT32_EQ(CFE_SB_CreatePipe(&PipeId, PipeDepth, PipeName), CFE_SB_BAD_ARGUMENT); + + UtAssert_INT32_EQ(CFE_SB_Global.HKTlmMsg.Payload.CreatePipeErrorCounter, 1); +} + +/* +** Test create pipe response to a null pipe name pointer. +*/ +void Test_CreatePipe_PipeName_NullPtr(void) +{ + CFE_SB_PipeId_t PipeId = SB_UT_PIPEID_0; + uint16 PipeDepth = 1; + + /* Call to CFE_SB_CreatePipe with empty PipeName should fail */ + UtAssert_INT32_EQ(CFE_SB_CreatePipe(&PipeId, PipeDepth, NULL), CFE_SB_PIPE_CR_ERR); + + UtAssert_INT32_EQ(CFE_SB_Global.HKTlmMsg.Payload.CreatePipeErrorCounter, 1); +} + /* ** Function for calling SB delete pipe API test functions */ diff --git a/modules/sb/ut-coverage/sb_UT.h b/modules/sb/ut-coverage/sb_UT.h index 6a4f59270..45e15fcf3 100644 --- a/modules/sb/ut-coverage/sb_UT.h +++ b/modules/sb/ut-coverage/sb_UT.h @@ -1198,6 +1198,21 @@ void Test_CreatePipe_InvalPipeDepth(void); ******************************************************************************/ void Test_CreatePipe_EmptyPipeName(void); +/*****************************************************************************/ +/** +** \brief Test create pipe response to a NULL pipe name +** +** \par Description +** This function tests the create pipe response to a null pipe name pointer. +** +** \par Assumptions, External Events, and Notes: +** None +** +** \returns +** This function does not return a value. +******************************************************************************/ +void Test_CreatePipe_PipeName_NullPtr(void); + /*****************************************************************************/ /** ** \brief Test create pipe response to a pipe name longer than allowed