diff --git a/elf2cfetbl.c b/elf2cfetbl.c index 182f7c4..dc85ac5 100644 --- a/elf2cfetbl.c +++ b/elf2cfetbl.c @@ -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') { @@ -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')) { @@ -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 */ @@ -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) @@ -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); + } } } }