The bucket chain should not contain loops. If it does we should mark the
hash bucket chain as invalid. This is easily checked by noticing when we
have seen more than the number of chain elements. Which equals the max
number as symbols in the table.
https://sourceware.org/bugzilla/show_bug.cgi?id=23011
Signed-off-by: Mark Wielaard <mark@klomp.org>
+2018-03-28 Mark Wielaard <mark@klomp.org>
+
+ * readelf.c (handle_sysv_hash): Break bucket chain after nchain
+ entries are found.
+ (handle_sysv_hash64): Likewise.
+
2018-03-27 Mark Wielaard <mark@klomp.org>
* readelf.c (attr_callback): Print dwarf_dieoffset as %PRIx64,
for (Elf32_Word cnt = 0; cnt < nbucket; ++cnt)
{
Elf32_Word inner = bucket[cnt];
+ Elf32_Word chain_len = 0;
while (inner > 0 && inner < nchain)
{
++nsyms;
+ ++chain_len;
+ if (chain_len > nchain)
+ goto invalid_data;
if (maxlength < ++lengths[cnt])
++maxlength;
for (Elf64_Xword cnt = 0; cnt < nbucket; ++cnt)
{
Elf64_Xword inner = bucket[cnt];
+ Elf64_Xword chain_len = 0;
while (inner > 0 && inner < nchain)
{
++nsyms;
+ ++chain_len;
+ if (chain_len > nchain)
+ goto invalid_data;
if (maxlength < ++lengths[cnt])
++maxlength;