Skip to content

Commit

Permalink
Merge pull request #2440 from chillfig:add_emptyString_check
Browse files Browse the repository at this point in the history
Fix #2436, Adds an empty string or null pointer check for pipe creation
  • Loading branch information
dzbaker committed Oct 12, 2023
2 parents f5ce0f6 + 58551ac commit 4979388
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
28 changes: 25 additions & 3 deletions modules/sb/ut-coverage/sb_UT.c
Original file line number Diff line number Diff line change
Expand Up @@ -1646,6 +1646,7 @@ void Test_CreatePipe_API(void)
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);
}

/*
Expand Down Expand Up @@ -1804,9 +1805,9 @@ void Test_CreatePipe_SamePipeName(void)
*/
void Test_CreatePipe_EmptyPipeName(void)
{
CFE_SB_PipeId_t PipeId = SB_UT_PIPEID_0;
uint16 PipeDepth = 1;
char PipeName[] = "";
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);
Expand All @@ -1815,6 +1816,27 @@ void Test_CreatePipe_EmptyPipeName(void)
}

/*
** 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;

/* To fail the pipe create, force the OS_QueueCreate call to return some
* type of error code.
*/
UT_SetDeferredRetcode(UT_KEY(OS_QueueCreate), 1, OS_ERR_NO_FREE_IDS);

/* 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
*/
void Test_DeletePipe_API(void)
Expand Down
15 changes: 15 additions & 0 deletions modules/sb/ut-coverage/sb_UT.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4979388

Please sign in to comment.