+2020-04-26 Alan Modra <amodra@gmail.com>
+
+ * readelf.c (get_num_dynamic_syms): Check DT_MIPS_XHASH was
+ read before dereferencing, and gracefully return. Remove
+ gnu_hash_error variable. Free gnu hash arrays if number of
+ syms found is zero.
+
2020-04-24 Alan Modra <amodra@gmail.com>
* readelf.c (get_num_dynamic_syms): Check for nbuckets and nchains
bfd_vma i, maxchain = 0xffffffff, bitmaskwords;
bfd_vma buckets_vma;
unsigned long hn;
- bfd_boolean gnu_hash_error = FALSE;
if (fseek (filedata->handle,
(filedata->archive_file_offset
SEEK_SET))
{
error (_("Unable to seek to start of dynamic information\n"));
- gnu_hash_error = TRUE;
goto no_gnu_hash;
}
if (fread (nb, 16, 1, filedata->handle) != 1)
{
error (_("Failed to read in number of buckets\n"));
- gnu_hash_error = TRUE;
goto no_gnu_hash;
}
SEEK_SET))
{
error (_("Unable to seek to start of dynamic information\n"));
- gnu_hash_error = TRUE;
goto no_gnu_hash;
}
= get_dynamic_data (filedata, filedata->ngnubuckets, 4);
if (filedata->gnubuckets == NULL)
- {
- gnu_hash_error = TRUE;
- goto no_gnu_hash;
- }
+ goto no_gnu_hash;
for (i = 0; i < filedata->ngnubuckets; i++)
if (filedata->gnubuckets[i] != 0)
{
if (filedata->gnubuckets[i] < filedata->gnusymidx)
- {
- gnu_hash_error = TRUE;
- goto no_gnu_hash;
- }
+ goto no_gnu_hash;
if (maxchain == 0xffffffff || filedata->gnubuckets[i] > maxchain)
maxchain = filedata->gnubuckets[i];
}
if (maxchain == 0xffffffff)
- {
- gnu_hash_error = TRUE;
- goto no_gnu_hash;
- }
+ goto no_gnu_hash;
maxchain -= filedata->gnusymidx;
SEEK_SET))
{
error (_("Unable to seek to start of dynamic information\n"));
- gnu_hash_error = TRUE;
goto no_gnu_hash;
}
if (fread (nb, 4, 1, filedata->handle) != 1)
{
error (_("Failed to determine last chain length\n"));
- gnu_hash_error = TRUE;
goto no_gnu_hash;
}
if (maxchain + 1 == 0)
- {
- gnu_hash_error = TRUE;
- goto no_gnu_hash;
- }
+ goto no_gnu_hash;
++maxchain;
}
SEEK_SET))
{
error (_("Unable to seek to start of dynamic information\n"));
- gnu_hash_error = TRUE;
goto no_gnu_hash;
}
filedata->ngnuchains = maxchain;
if (filedata->gnuchains == NULL)
- {
- gnu_hash_error = TRUE;
- goto no_gnu_hash;
- }
+ goto no_gnu_hash;
if (filedata->dynamic_info_DT_MIPS_XHASH)
{
SEEK_SET))
{
error (_("Unable to seek to start of dynamic information\n"));
- gnu_hash_error = TRUE;
goto no_gnu_hash;
}
filedata->mipsxlat = get_dynamic_data (filedata, maxchain, 4);
+ if (filedata->mipsxlat == NULL)
+ goto no_gnu_hash;
}
for (hn = 0; hn < filedata->ngnubuckets; ++hn)
&& (filedata->gnuchains[off++] & 1) == 0);
}
- no_gnu_hash:
- if (gnu_hash_error)
+ if (num_of_syms == 0)
{
+ no_gnu_hash:
if (filedata->mipsxlat)
{
free (filedata->mipsxlat);