MCPcopy Create free account
hub / github.com/coreboot/coreboot / phdr_read

Function phdr_read

util/cbfstool/elfheaders.c:238–278  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

236}
237
238static int
239phdr_read(const struct buffer *in, struct parsed_elf *pelf,
240 struct xdr *xdr, int bit64)
241{
242 struct buffer b;
243 Elf64_Phdr *phdr;
244 Elf64_Ehdr *ehdr;
245 int i;
246
247 ehdr = &pelf->ehdr;
248 /* cons up an input buffer for the headers.
249 * Note that the program headers can be anywhere,
250 * per the ELF spec, You'd be surprised how many ELF
251 * readers miss this little detail.
252 */
253 buffer_splice(&b, in, ehdr->e_phoff,
254 (uint32_t)ehdr->e_phentsize * ehdr->e_phnum);
255 if (check_size(in, ehdr->e_phoff, buffer_size(&b), "program headers"))
256 return -1;
257
258 /* gather up all the phdrs.
259 * We do them all at once because there is more
260 * than one loop over all the phdrs.
261 */
262 phdr = calloc(ehdr->e_phnum, sizeof(*phdr));
263 for (i = 0; i < ehdr->e_phnum; i++) {
264 DEBUG("Parsing segment %d\n", i);
265 elf_phdr(&b, &phdr[i], ehdr->e_phentsize, xdr, bit64);
266
267 /* Ensure the contents are valid within the elf file. */
268 if (check_size(in, phdr[i].p_offset, phdr[i].p_filesz,
269 "segment contents")) {
270 free(phdr);
271 return -1;
272 }
273 }
274
275 pelf->phdr = phdr;
276
277 return 0;
278}
279
280static int
281shdr_read(const struct buffer *in, struct parsed_elf *pelf,

Callers 1

parse_elfFunction · 0.85

Calls 6

buffer_spliceFunction · 0.85
check_sizeFunction · 0.85
buffer_sizeFunction · 0.85
elf_phdrFunction · 0.85
callocFunction · 0.50
freeFunction · 0.50

Tested by

no test coverage detected