Skip to content

Commit

Permalink
Fix nasa#2581, Adding bytes read check
Browse files Browse the repository at this point in the history
  • Loading branch information
tvisha.s.andharia committed Jul 22, 2024
1 parent d0e9564 commit 13c35a5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 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 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

0 comments on commit 13c35a5

Please sign in to comment.