Skip to content

Commit

Permalink
Fix #85, Check Return Value of fseek
Browse files Browse the repository at this point in the history
  • Loading branch information
arielswalker committed Sep 23, 2021
1 parent 2b68c4b commit 0a93f98
Showing 1 changed file with 49 additions and 5 deletions.
54 changes: 49 additions & 5 deletions elf2cfetbl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1741,7 +1741,15 @@ int32 GetSectionHeader(int32 SectionIndex, union Elf_Shdr *SectionHeader)
SeekOffset = SectionHeaderStringTableDataOffset + get_sh_name(SectionHeader);
if (Verbose)
printf(" sh_name = 0x%08x - ", get_sh_name(SectionHeader));
fseek(SrcFileDesc, SeekOffset, SEEK_SET);
Status = fseek(SrcFileDesc, SeekOffset, SEEK_SET);
if (Status != 0)
{
printf("Error locating Section Header #%d in file '%s'\n", SectionIndex, SrcFilename);
return FAILED;
}
else {
fseek(SrcFileDesc, SeekOffset, SEEK_SET);
}

while ((VerboseStr[i] = fgetc(SrcFileDesc)) != '\0')
{
Expand Down Expand Up @@ -1922,7 +1930,16 @@ int32 GetSymbol(int32 SymbolIndex, union Elf_Sym *Symbol)
SeekOffset = StringTableDataOffset + get_st_name(Symbol);
if (Verbose)
printf(" st_name = 0x%08x - ", get_st_name(Symbol));
fseek(SrcFileDesc, SeekOffset, SEEK_SET);
Status = fseek(SrcFileDesc, SeekOffset, SEEK_SET);
if (Status != 0)
{
printf("Error locating Section Header #%d in file '%s'\n", SectionIndex, SrcFilename);
return FAILED;
}
else
{
fseek(SrcFileDesc, SeekOffset, SEEK_SET);
}

while ((i < sizeof(VerboseStr)) && ((VerboseStr[i] = fgetc(SrcFileDesc)) != '\0'))
{
Expand Down Expand Up @@ -2275,7 +2292,16 @@ int32 GetTblDefInfo(void)
printf("Error: SeekOffset may not be %lu\n", (long unsigned int)calculated_offset);
Status = FAILED;
}
fseek(SrcFileDesc, SeekOffset, SEEK_SET);
Status = fseek(SrcFileDesc, SeekOffset, SEEK_SET);
if (Status != 0)
{
printf("Error locating Section Header #%d in file '%s'\n", SectionIndex, SrcFilename);
return FAILED;
}
else
{
fseek(SrcFileDesc, SeekOffset, SEEK_SET);
}
NumDefsRead = fread(&TblFileDef, sizeof(CFE_TBL_FileDef_t), 1, SrcFileDesc);

/* ensuring all are strings are null-terminated */
Expand Down Expand Up @@ -2429,7 +2455,16 @@ int32 LocateAndReadUserObject(void)
printf("Error: SeekOffset may not be %lu\n", (long unsigned int)calculated_offset);
Status = FAILED;
}
fseek(SrcFileDesc, SeekOffset, SEEK_SET);
Status = fseek(SrcFileDesc, SeekOffset, SEEK_SET);
if (Status != 0)
{
printf("Error locating Section Header #%d in file '%s'\n", SectionIndex, SrcFilename);
return FAILED;
}
else
{
fseek(SrcFileDesc, SeekOffset, SEEK_SET);
}

/* Determine if the elf file contained the size of the object */
if (get_st_size(SymbolPtrs[UserObjSymbolIndex]) != 0)
Expand Down Expand Up @@ -2471,7 +2506,16 @@ int32 LocateAndReadUserObject(void)
}
}
/* Reset the file pointer */
fseek(SrcFileDesc, SeekOffset, SEEK_SET);
Status = fseek(SrcFileDesc, SeekOffset, SEEK_SET);
if (Status != 0)
{
printf("Error locating Section Header #%d in file '%s'\n", SectionIndex, SrcFilename);
return FAILED;
}
else
{
fseek(SrcFileDesc, SeekOffset, SEEK_SET);
}
}
}
}
Expand Down

0 comments on commit 0a93f98

Please sign in to comment.