diff options
author | emaste <emaste@FreeBSD.org> | 2014-07-23 14:30:58 +0000 |
---|---|---|
committer | emaste <emaste@FreeBSD.org> | 2014-07-23 14:30:58 +0000 |
commit | 35d9abcb8d9ec0494bd89b56ca40aa22b6206e54 (patch) | |
tree | 56cbc2d6e52a0abc22437d1f292fbebf39484ad7 /usr.sbin/kldxref | |
parent | 68543b825eebc8f694e1463a03bfde0c02ac0e89 (diff) | |
download | FreeBSD-src-35d9abcb8d9ec0494bd89b56ca40aa22b6206e54.zip FreeBSD-src-35d9abcb8d9ec0494bd89b56ca40aa22b6206e54.tar.gz |
MFC r265157: kldxref: Clean up error reporting
Omit "too many sections" warnings if the ELF file is not dynamically
linked (and is therefore skipped anyway), and otherwise output it only
once. An errant core file would previously cause kldxref to output a
number of warnings.
Also introduce a MAXSEGS #define and replace literal 2 with it, to make
comparisons clear.
Reviewed by: kib
Sponsored by: The FreeBSD Foundation
Diffstat (limited to 'usr.sbin/kldxref')
-rw-r--r-- | usr.sbin/kldxref/ef.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/usr.sbin/kldxref/ef.c b/usr.sbin/kldxref/ef.c index b683898..88fbc34 100644 --- a/usr.sbin/kldxref/ef.c +++ b/usr.sbin/kldxref/ef.c @@ -47,6 +47,7 @@ #include "ef.h" +#define MAXSEGS 2 struct ef_file { char* ef_name; struct elf_file *ef_efile; @@ -68,7 +69,7 @@ struct ef_file { Elf_Off ef_symoff; Elf_Sym* ef_symtab; int ef_nsegs; - Elf_Phdr * ef_segs[2]; + Elf_Phdr * ef_segs[MAXSEGS]; int ef_verbose; Elf_Rel * ef_rel; /* relocation table */ int ef_relsz; /* number of entries */ @@ -580,12 +581,9 @@ ef_open(const char *filename, struct elf_file *efile, int verbose) ef_print_phdr(phdr); switch (phdr->p_type) { case PT_LOAD: - if (nsegs == 2) { - warnx("%s: too many sections", - filename); - break; - } - ef->ef_segs[nsegs++] = phdr; + if (nsegs < MAXSEGS) + ef->ef_segs[nsegs] = phdr; + nsegs++; break; case PT_PHDR: break; @@ -597,12 +595,15 @@ ef_open(const char *filename, struct elf_file *efile, int verbose) } if (verbose > 1) printf("\n"); - ef->ef_nsegs = nsegs; if (phdyn == NULL) { warnx("Skipping %s: not dynamically-linked", filename); break; + } else if (nsegs > MAXSEGS) { + warnx("%s: too many sections", filename); + break; } + ef->ef_nsegs = nsegs; if (ef_read_entry(ef, phdyn->p_offset, phdyn->p_filesz, (void**)&ef->ef_dyn) != 0) { printf("ef_read_entry failed\n"); |