diff --git a/modules/fs/fsw/src/cfe_fs_api.c b/modules/fs/fsw/src/cfe_fs_api.c index 40812f7b2..47e19a19c 100644 --- a/modules/fs/fsw/src/cfe_fs_api.c +++ b/modules/fs/fsw/src/cfe_fs_api.c @@ -138,6 +138,12 @@ CFE_Status_t CFE_FS_ReadHeader(CFE_FS_Header_t *Hdr, osal_id_t FileDes) */ OsStatus = OS_read(FileDes, Hdr, sizeof(CFE_FS_Header_t)); + /* Check if the read was successful */ + if (OsStatus != sizeof(CFE_FS_Header_t)) + { + return CFE_STATUS_EXTERNAL_RESOURCE_FAIL; + } + /* Determine if this processor is a little endian processor */ /* cppcheck-suppress knownConditionTrueFalse */ if ((*(char *)(&EndianCheck)) == 0x04) diff --git a/modules/fs/ut-coverage/fs_UT.c b/modules/fs/ut-coverage/fs_UT.c index 36ace51e8..75147816d 100644 --- a/modules/fs/ut-coverage/fs_UT.c +++ b/modules/fs/ut-coverage/fs_UT.c @@ -122,6 +122,11 @@ void Test_CFE_FS_ReadHeader(void) UT_SetDefaultReturnValue(UT_KEY(OS_read), OS_ERROR); UtAssert_INT32_EQ(CFE_FS_ReadHeader(&Hdr, FileDes), CFE_STATUS_EXTERNAL_RESOURCE_FAIL); + /* Test partial success with reading header */ + UT_InitData(); + UT_SetDefaultReturnValue(UT_KEY(OS_read), 1); + UtAssert_INT32_EQ(CFE_FS_ReadHeader(&Hdr, FileDes), CFE_STATUS_EXTERNAL_RESOURCE_FAIL); + /* Test successfully reading the header */ UT_InitData(); UtAssert_INT32_EQ(CFE_FS_ReadHeader(&Hdr, FileDes), sizeof(Hdr));