This is an archive of the discontinued LLVM Phabricator instance.

[llvm-readobj] - Do not crash when GnuHashTable->symndx is greater than the dynamic symbols count.
ClosedPublic

Authored by grimar on Jun 16 2020, 7:07 AM.

Details

Summary

Elf_GnuHash_Impl has the following method:

ArrayRef<Elf_Word> values(unsigned DynamicSymCount) const {
  return ArrayRef<Elf_Word>(buckets().end(), DynamicSymCount - symndx);
}

When DynamicSymCount is less than symndx we return an array with the huge broken size.
This patch fixes the issue ans adds an assert. This assert helped to fix an issue
in one of the test cases.

The printGnuHashHistogram method also needs to be fixed. I am planning to fix it
independently after we land the D81928, which will allow to reuse the code that validates
the GNU hash table before the dumping.

Depends on: D81928

Diff Detail

Event Timeline

grimar created this revision.Jun 16 2020, 7:07 AM
Herald added a project: Restricted Project. · View Herald Transcript
grimar marked an inline comment as done.Jun 16 2020, 7:11 AM
grimar added inline comments.
llvm/test/tools/llvm-readobj/ELF/hash-histogram.test
258

I had to fix this test case because this place was wrong and the code adds an assert:
assert(DynamicSymCount >= symndx); which is triggered if this test case is not fixed.

We still want to make this assert never happen. I've mentioned in the description that it
is related to printGnuHashHistogram and probably should be fixed independently.

MaskRay accepted this revision.Jun 16 2020, 10:22 PM

Looks great!

This revision is now accepted and ready to land.Jun 16 2020, 10:22 PM
jhenderson accepted this revision.Jun 17 2020, 12:32 AM

LGTM, with nit.

llvm/test/tools/llvm-readobj/ELF/hash-histogram.test
214–215

whilst you're modifying this line: "described with" -> "described by"

This revision was automatically updated to reflect the committed changes.