changeset 14147:6d4e8fd19fe1

4004 dis(1) can't deal with extended sections Reviewed by: Jason King <jason.brian.king@gmail.com> Reviewed by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net> Approved by: Robert Mustacchi <rm@joyent.com>
author Richard Lowe <richlowe@richlowe.net>
date Tue, 06 Aug 2013 21:49:47 -0400
parents 51c57658a98a
children fe28bd725808
files usr/src/cmd/dis/dis_target.c
diffstat 1 files changed, 10 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/cmd/dis/dis_target.c	Tue Aug 06 21:29:05 2013 -0400
+++ b/usr/src/cmd/dis/dis_target.c	Tue Aug 06 21:49:47 2013 -0400
@@ -446,6 +446,7 @@
 	current = tgt;
 	cmd = ELF_C_READ;
 	while ((elf = elf_begin(tgt->dt_fd, cmd, tgt->dt_elf_root)) != NULL) {
+		size_t shnum = 0;
 
 		if (elf_kind(tgt->dt_elf_root) == ELF_K_AR &&
 		    (arhdr = elf_getarhdr(elf)) == NULL) {
@@ -501,9 +502,16 @@
 			return (NULL);
 		}
 
+		if (elf_getshdrnum(elf, &shnum) == -1) {
+			warn("%s: failed to get number of sections in file",
+			    file);
+			dis_tgt_destroy(tgt);
+			return (NULL);
+		}
+
 		current->dt_shnmap = safe_malloc(sizeof (dis_shnmap_t) *
-		    ehdr.e_shnum);
-		current->dt_shncount = ehdr.e_shnum;
+		    shnum);
+		current->dt_shncount = shnum;
 
 		idx = 0;
 		dis_tgt_section_iter(current, tgt_scn_init, &idx);