Skip to content

Commit

Permalink
Fix nasa#2436, Adds an empty string or null pointer check for pipe cr…
Browse files Browse the repository at this point in the history
…eation
  • Loading branch information
jdfiguer authored and jdfiguer committed Sep 7, 2023
1 parent 798d557 commit a650f2b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions modules/cfe_testcase/src/sb_pipe_mang_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion modules/sb/fsw/src/cfe_sb_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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[0] == '\0')
{
PendingEventId = CFE_SB_CR_PIPE_BAD_ARG_EID;
Status = CFE_SB_BAD_ARGUMENT;
Expand Down
15 changes: 15 additions & 0 deletions modules/sb/ut-coverage/sb_UT.c
Original file line number Diff line number Diff line change
Expand Up @@ -1798,6 +1798,21 @@ 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_PIPE_CR_ERR);

UtAssert_INT32_EQ(CFE_SB_Global.HKTlmMsg.Payload.CreatePipeErrorCounter, 1);
}

/*
** Function for calling SB delete pipe API test functions
*/
Expand Down

0 comments on commit a650f2b

Please sign in to comment.