| 384 | } |
| 385 | |
| 386 | static int strtab_read(const struct buffer *in, struct parsed_elf *pelf) |
| 387 | { |
| 388 | Elf64_Ehdr *ehdr; |
| 389 | Elf64_Word i; |
| 390 | |
| 391 | ehdr = &pelf->ehdr; |
| 392 | |
| 393 | if (ehdr->e_shstrndx >= ehdr->e_shnum) { |
| 394 | ERROR("Section header string table index out of range: %d\n", |
| 395 | ehdr->e_shstrndx); |
| 396 | return -1; |
| 397 | } |
| 398 | |
| 399 | /* For each section of type SHT_STRTAB create a symtab buffer. */ |
| 400 | pelf->strtabs = calloc(ehdr->e_shnum, sizeof(struct buffer *)); |
| 401 | |
| 402 | for (i = 0; i < ehdr->e_shnum; i++) { |
| 403 | struct buffer *b; |
| 404 | Elf64_Shdr *shdr = &pelf->shdr[i]; |
| 405 | |
| 406 | if (shdr->sh_type != SHT_STRTAB) |
| 407 | continue; |
| 408 | |
| 409 | b = calloc(1, sizeof(*b)); |
| 410 | buffer_splice(b, in, shdr->sh_offset, shdr->sh_size); |
| 411 | if (check_size(in, shdr->sh_offset, buffer_size(b), "strtab")) { |
| 412 | ERROR("STRTAB section not within bounds: %d\n", i); |
| 413 | free(b); |
| 414 | return -1; |
| 415 | } |
| 416 | pelf->strtabs[i] = b; |
| 417 | } |
| 418 | |
| 419 | return 0; |
| 420 | } |
| 421 | |
| 422 | static int |
| 423 | symtab_read(const struct buffer *in, struct parsed_elf *pelf, |
no test coverage detected