diff options
author | emaste <emaste@FreeBSD.org> | 2015-05-14 19:48:15 +0000 |
---|---|---|
committer | emaste <emaste@FreeBSD.org> | 2015-05-14 19:48:15 +0000 |
commit | a4c24f2588a858878b30f781ab7780f8a7565dec (patch) | |
tree | 68f789ad3decb5c1b82f63186eaf665cb84861ee /contrib/elftoolchain/readelf | |
parent | 01699072e4f2583fa587d2aea44d8062f228b9cd (diff) | |
download | FreeBSD-src-a4c24f2588a858878b30f781ab7780f8a7565dec.zip FreeBSD-src-a4c24f2588a858878b30f781ab7780f8a7565dec.tar.gz |
Update to ELF Tool Chain r3197
Highlights:
- Fix man page markup, whitespace, and typos
- Fix sh_info of SHT_GROUP section to point to the correct string
- Improve validation in readelf and elfcopy/strip
- Handle DWARF 4's DW_AT_high_pc in addr2line
Sponsored by: The FreeBSD Foundation
Diffstat (limited to 'contrib/elftoolchain/readelf')
-rw-r--r-- | contrib/elftoolchain/readelf/readelf.1 | 4 | ||||
-rw-r--r-- | contrib/elftoolchain/readelf/readelf.c | 32 |
2 files changed, 24 insertions, 12 deletions
diff --git a/contrib/elftoolchain/readelf/readelf.1 b/contrib/elftoolchain/readelf/readelf.1 index 8419d95..a71e85f 100644 --- a/contrib/elftoolchain/readelf/readelf.1 +++ b/contrib/elftoolchain/readelf/readelf.1 @@ -22,7 +22,7 @@ .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.\" $Id: readelf.1 3059 2014-06-02 00:42:32Z kaiwang27 $ +.\" $Id: readelf.1 3195 2015-05-12 17:22:19Z emaste $ .\" .Dd September 13, 2012 .Os @@ -194,4 +194,4 @@ separate lines. The .Nm utility was written by -.An "Kai Wang" Aq kaiwang27@users.sourceforge.net . +.An Kai Wang Aq Mt kaiwang27@users.sourceforge.net . diff --git a/contrib/elftoolchain/readelf/readelf.c b/contrib/elftoolchain/readelf/readelf.c index bca228c..29bc389 100644 --- a/contrib/elftoolchain/readelf/readelf.c +++ b/contrib/elftoolchain/readelf/readelf.c @@ -46,7 +46,7 @@ #include "_elftc.h" -ELFTC_VCSID("$Id: readelf.c 3178 2015-03-30 18:29:13Z emaste $"); +ELFTC_VCSID("$Id: readelf.c 3189 2015-04-20 17:02:01Z emaste $"); /* * readelf(1) options. @@ -2673,7 +2673,7 @@ dump_phdr(struct readelf *re) { const char *rawfile; GElf_Phdr phdr; - size_t phnum; + size_t phnum, size; int i, j; #define PH_HDR "Type", "Offset", "VirtAddr", "PhysAddr", "FileSiz", \ @@ -2726,10 +2726,14 @@ dump_phdr(struct readelf *re) " 0x%16.16jx 0x%16.16jx %c%c%c" " %#jx\n", PH_CT); if (phdr.p_type == PT_INTERP) { - if ((rawfile = elf_rawfile(re->elf, NULL)) == NULL) { + if ((rawfile = elf_rawfile(re->elf, &size)) == NULL) { warnx("elf_rawfile failed: %s", elf_errmsg(-1)); continue; } + if (phdr.p_offset >= size) { + warnx("invalid program header offset"); + continue; + } printf(" [Requesting program interpreter: %s]\n", rawfile + phdr.p_offset); } @@ -4378,13 +4382,22 @@ dump_mips_options(struct readelf *re, struct section *s) p = d->d_buf; pe = p + d->d_size; while (p < pe) { + if (pe - p < 8) { + warnx("Truncated MIPS option header"); + return; + } kind = re->dw_decode(&p, 1); size = re->dw_decode(&p, 1); sndx = re->dw_decode(&p, 2); info = re->dw_decode(&p, 4); + if (size < 8 || size - 8 > pe - p) { + warnx("Malformed MIPS option header"); + return; + } + size -= 8; switch (kind) { case ODK_REGINFO: - dump_mips_odk_reginfo(re, p, size - 8); + dump_mips_odk_reginfo(re, p, size); break; case ODK_EXCEPTIONS: printf(" EXCEPTIONS FPU_MIN: %#x\n", @@ -4435,7 +4448,7 @@ dump_mips_options(struct readelf *re, struct section *s) default: break; } - p += size - 8; + p += size; } } @@ -7458,11 +7471,10 @@ main(int argc, char **argv) errx(EXIT_FAILURE, "ELF library initialization failed: %s", elf_errmsg(-1)); - for (i = 0; i < argc; i++) - if (argv[i] != NULL) { - re->filename = argv[i]; - dump_object(re); - } + for (i = 0; i < argc; i++) { + re->filename = argv[i]; + dump_object(re); + } exit(EXIT_SUCCESS); } |