llvm.org GIT mirror llvm / ddec8ab
Centralize sh_entsize checking. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@283455 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 3 years ago
2 changed file(s) with 4 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
117117 Elf_Sym_Range symbols(const Elf_Shdr *Sec) const {
118118 if (!Sec)
119119 return makeArrayRef(nullptr, nullptr);
120 if (Sec->sh_entsize != sizeof(Elf_Sym))
121 report_fatal_error("Invalid symbol size");
122120 auto V = getSectionContentsAsArray(Sec);
123121 if (!V)
124122 report_fatal_error(V.getError().message());
126124 }
127125
128126 Elf_Rela_Range relas(const Elf_Shdr *Sec) const {
129 if (Sec->sh_entsize != sizeof(Elf_Rela))
130 report_fatal_error("Invalid relocation entry size");
131127 auto V = getSectionContentsAsArray(Sec);
132128 if (!V)
133129 report_fatal_error(V.getError().message());
135131 }
136132
137133 Elf_Rel_Range rels(const Elf_Shdr *Sec) const {
138 if (Sec->sh_entsize != sizeof(Elf_Rel))
139 report_fatal_error("Invalid relocation entry size");
140134 auto V = getSectionContentsAsArray(Sec);
141135 if (!V)
142136 report_fatal_error(V.getError().message());
223217 template
224218 ErrorOr>
225219 ELFFile::getSectionContentsAsArray(const Elf_Shdr *Sec) const {
220 if (Sec->sh_entsize != sizeof(T) && sizeof(T) != 1)
221 return object_error::parse_failed;
222
226223 uintX_t Offset = Sec->sh_offset;
227224 uintX_t Size = Sec->sh_size;
228225
3434 SECTION-NEXT: EntrySize: 32
3535
3636 RUN: not llvm-readobj -t %p/Inputs/invalid-sh_entsize.elf 2>&1 | FileCheck --check-prefix=INVALID-SYM-SIZE %s
37 INVALID-SYM-SIZE: Invalid symbol size
37 INVALID-SYM-SIZE: Invalid data was encountered while parsing the file
3838
3939 RUN: not llvm-readobj --dyn-symbols %p/Inputs/invalid-sh_entsize.elf 2>&1 | FileCheck --check-prefix=INVALID-DYNSYM-SIZE %s
4040 INVALID-DYNSYM-SIZE: Invalid entity size