diff options
author | marcel <marcel@FreeBSD.org> | 2014-06-19 20:12:28 +0000 |
---|---|---|
committer | marcel <marcel@FreeBSD.org> | 2014-06-19 20:12:28 +0000 |
commit | beb0a51a20ea562bc2802e4a20cad2b4233efe2a (patch) | |
tree | 2c071183b2508eb1c0a1558bb50c7a79fc5b4040 /usr.bin/elfdump | |
parent | f13b1f884484db04939563945a046f40f0580f85 (diff) | |
download | FreeBSD-src-beb0a51a20ea562bc2802e4a20cad2b4233efe2a.zip FreeBSD-src-beb0a51a20ea562bc2802e4a20cad2b4233efe2a.tar.gz |
Don't dump core when the ELF file has no section headers. The ELF
core files created by gcore are among those.
Diffstat (limited to 'usr.bin/elfdump')
-rw-r--r-- | usr.bin/elfdump/elfdump.c | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/usr.bin/elfdump/elfdump.c b/usr.bin/elfdump/elfdump.c index c86e6fc..2f1461e 100644 --- a/usr.bin/elfdump/elfdump.c +++ b/usr.bin/elfdump/elfdump.c @@ -495,11 +495,19 @@ main(int ac, char **av) phnum = elf_get_quarter(e, e, E_PHNUM); shentsize = elf_get_quarter(e, e, E_SHENTSIZE); p = (char *)e + phoff; - sh = (char *)e + shoff; - shnum = elf_get_shnum(e, sh); - shstrndx = elf_get_shstrndx(e, sh); - offset = elf_get_off(e, (char *)sh + shstrndx * shentsize, SH_OFFSET); - shstrtab = (char *)e + offset; + if (shoff > 0) { + sh = (char *)e + shoff; + shnum = elf_get_shnum(e, sh); + shstrndx = elf_get_shstrndx(e, sh); + offset = elf_get_off(e, (char *)sh + shstrndx * shentsize, + SH_OFFSET); + shstrtab = (char *)e + offset; + } else { + sh = NULL; + shnum = 0; + shstrndx = 0; + shstrtab = NULL; + } for (i = 0; (u_int64_t)i < shnum; i++) { name = elf_get_word(e, (char *)sh + i * shentsize, SH_NAME); offset = elf_get_off(e, (char *)sh + i * shentsize, SH_OFFSET); @@ -616,8 +624,6 @@ elf_print_ehdr(Elf32_Ehdr *e, void *sh) phentsize = elf_get_quarter(e, e, E_PHENTSIZE); phnum = elf_get_quarter(e, e, E_PHNUM); shentsize = elf_get_quarter(e, e, E_SHENTSIZE); - shnum = elf_get_shnum(e, sh); - shstrndx = elf_get_shstrndx(e, sh); fprintf(out, "\nelf header:\n"); fprintf(out, "\n"); fprintf(out, "\te_ident: %s %s %s\n", ei_classes[class], ei_data[data], @@ -633,8 +639,12 @@ elf_print_ehdr(Elf32_Ehdr *e, void *sh) fprintf(out, "\te_phentsize: %jd\n", (intmax_t)phentsize); fprintf(out, "\te_phnum: %jd\n", (intmax_t)phnum); fprintf(out, "\te_shentsize: %jd\n", (intmax_t)shentsize); - fprintf(out, "\te_shnum: %jd\n", (intmax_t)shnum); - fprintf(out, "\te_shstrndx: %jd\n", (intmax_t)shstrndx); + if (sh != NULL) { + shnum = elf_get_shnum(e, sh); + shstrndx = elf_get_shstrndx(e, sh); + fprintf(out, "\te_shnum: %jd\n", (intmax_t)shnum); + fprintf(out, "\te_shstrndx: %jd\n", (intmax_t)shstrndx); + } } static void @@ -697,6 +707,11 @@ elf_print_shdr(Elf32_Ehdr *e, void *sh) void *v; int i; + if (sh == NULL) { + fprintf(out, "\nNo section headers\n"); + return; + } + shentsize = elf_get_quarter(e, e, E_SHENTSIZE); shnum = elf_get_shnum(e, sh); fprintf(out, "\nsection header:\n"); |