From 45ab4e140953e56f77a460aee7d1ec7a20433e81 Mon Sep 17 00:00:00 2001 From: Jacob Hageman Date: Tue, 18 Jan 2022 15:34:58 -0700 Subject: [PATCH] Fix #1210, Set output in OS_stat handler --- src/ut-stubs/osapi-file-handlers.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/ut-stubs/osapi-file-handlers.c b/src/ut-stubs/osapi-file-handlers.c index ac200dbcf..b62428f65 100644 --- a/src/ut-stubs/osapi-file-handlers.c +++ b/src/ut-stubs/osapi-file-handlers.c @@ -192,13 +192,20 @@ void UT_DefaultHandler_OS_TimedWrite(void *UserObj, UT_EntryKey_t FuncKey, const void UT_DefaultHandler_OS_stat(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) { os_fstat_t *filestats = UT_Hook_GetArgValueByName(Context, "filestats", os_fstat_t *); + size_t CopySize; int32 Status; UT_Stub_GetInt32StatusCode(Context, &Status); if (Status == OS_SUCCESS) { - UT_Stub_CopyToLocal(UT_KEY(OS_stat), filestats, sizeof(*filestats)); + CopySize = UT_Stub_CopyToLocal(UT_KEY(OS_stat), filestats, sizeof(*filestats)); + + /* Ensure memory is set if not provided by test */ + if (CopySize < sizeof(*filestats)) + { + memset(filestats, 0, sizeof(*filestats)); + } } }