Index: readelf/readelf.c =================================================================== --- readelf/readelf.c +++ readelf/readelf.c @@ -2924,6 +2924,10 @@ /* Determine the actual number of table entries. */ nentries = 0; + if (s->entsize == 0) { + warnx("Invalid dynamic section sh_entsize"); + return; + } jmax = (int) (s->sz / s->entsize); for (j = 0; j < jmax; j++) { @@ -3171,6 +3175,10 @@ else printf("%-12s %-12s %-19s %-16s %s\n", REL_HDR); } + if (s->entsize == 0) { + warnx("Invalid sh_entsize"); + return; + } len = d->d_size / s->entsize; for (i = 0; i < len; i++) { if (gelf_getrel(d, i, &r) != &r) { @@ -3227,6 +3235,10 @@ else printf("%-12s %-12s %-19s %-16s %s\n", RELA_HDR); } + if (s->entsize == 0) { + warnx("Invalid sh_entsize"); + return; + } len = d->d_size / s->entsize; for (i = 0; i < len; i++) { if (gelf_getrela(d, i, &r) != &r) { @@ -3305,6 +3317,10 @@ } if (d->d_size <= 0) return; + if (s->entsize == 0) { + warnx("Invalid symbol table sh_entsize"); + return; + } printf("Symbol table (%s)", s->name); printf(" contains %ju entries:\n", s->sz / s->entsize); printf("%7s%9s%14s%5s%8s%6s%9s%5s\n", "Num:", "Value", "Size", "Type", @@ -3373,6 +3389,10 @@ } if (d->d_size <= 0) return; + if (s->entsize == 0) { + warnx("Invalid dynamic section sh_entsize"); + return; + } for (i = 0; (uint64_t)i < s->sz / s->entsize; i++) { if (gelf_getdyn(d, i, &dyn) != &dyn) { @@ -3562,6 +3582,10 @@ maskwords = buf[2]; buf += 4; ds = &re->sl[s->link]; + if (ds->entsize == 0) { + warnx("Invalid .gnu.hash sh_entsize"); + return; + } dynsymcount = ds->sz / ds->entsize; nchain = dynsymcount - symndx; if (d->d_size != 4 * sizeof(uint32_t) + maskwords * @@ -4009,6 +4033,10 @@ continue; lib = d->d_buf; printf("\nLibrary list section '%s' ", s->name); + if (s->entsize == 0) { + warnx("Invalid sh_entsize"); + continue; + } printf("contains %ju entries:\n", s->sz / s->entsize); printf("%12s%24s%18s%10s%6s\n", "Library", "Time Stamp", "Checksum", "Version", "Flags"); @@ -4351,6 +4379,10 @@ } if (d->d_size <= 0) return; + if (s->entsize == 0) { + warnx("Invalid MIPS reginfo sh_entsize"); + return; + } printf("\nSection '%s' contains %ju entries:\n", s->name, s->sz / s->entsize);