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 #2581, Adding bytes read check #2584

Merged
merged 2 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
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
10 changes: 6 additions & 4 deletions modules/fs/fsw/src/cfe_fs_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -146,11 +152,7 @@ CFE_Status_t CFE_FS_ReadHeader(CFE_FS_Header_t *Hdr, osal_id_t FileDes)
/* its standard big-endian format into a little endian format to ease user access */
CFE_FS_ByteSwapCFEHeader(Hdr);
}
}

if (OsStatus >= OS_SUCCESS)
{
/* The "OsStatus" reflects size actually read */
Result = (long)OsStatus;
}
else
Expand Down
5 changes: 5 additions & 0 deletions modules/fs/ut-coverage/fs_UT.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Loading