Skip to content

Commit

Permalink
Fix #2026, CFE_FS_ParseInputFileNameEx avoid uninit var
Browse files Browse the repository at this point in the history
  • Loading branch information
skliper committed Jan 18, 2022
1 parent c161cf0 commit fbbd5a9
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 fbbd5a9

Please sign in to comment.