Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2026, CFE_FS_ParseInputFileNameEx avoid uninit var #2027

Merged
merged 1 commit into from
Jan 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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