Skip to content

Commit

Permalink
Merge pull request #2027 from skliper/fix2026-handle_parse_input_null…
Browse files Browse the repository at this point in the history
…default

Fix #2026, CFE_FS_ParseInputFileNameEx avoid uninit var #2027
  • Loading branch information
astrogeco committed Jan 19, 2022
2 parents 47d8d97 + fbbd5a9 commit 5cc196e
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions modules/core_api/ut-stubs/src/cfe_fs_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ void UT_DefaultHandler_CFE_FS_ParseInputFileNameEx(void *UserObj, UT_EntryKey_t
{
char * OutputBuffer = UT_Hook_GetArgValueByName(Context, "OutputBuffer", char *);
size_t OutputBufSize = UT_Hook_GetArgValueByName(Context, "OutputBufSize", size_t);
const char *InputBuffer = UT_Hook_GetArgValueByName(Context, "InputBuffer", const char *);
const char *DefaultInput = UT_Hook_GetArgValueByName(Context, "DefaultInput", const char *);

int32 status;
Expand All @@ -169,10 +170,18 @@ void UT_DefaultHandler_CFE_FS_ParseInputFileNameEx(void *UserObj, UT_EntryKey_t

/* Copy any specific output supplied by test case */
if (status >= 0 && UT_Stub_CopyToLocal(UT_KEY(CFE_FS_ParseInputFileNameEx), OutputBuffer, OutputBufSize) == 0 &&
OutputBufSize > 0 && DefaultInput != NULL)
OutputBufSize > 0)
{
/* Otherwise fall back to simple copy */
strncpy(OutputBuffer, DefaultInput, OutputBufSize);
if (DefaultInput != NULL)
{
/* Use default if set */
strncpy(OutputBuffer, DefaultInput, OutputBufSize);
}
else
{
/* Fall back to copy input to avoid uninitialized output */
strncpy(OutputBuffer, InputBuffer, OutputBufSize);
}
}
}

Expand Down

0 comments on commit 5cc196e

Please sign in to comment.