Print this page
4004 dis(1) can't deal with extended sections

@@ -444,10 +444,11 @@
         }
 
         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) {
                         warn("%s: malformed archive", file);
                         dis_tgt_destroy(tgt);

@@ -499,13 +500,20 @@
                             "file", file);
                         dis_tgt_destroy(tgt);
                         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);
                 current->dt_filename = file;