[PATCH] D80215: [llvm-readelf] - --elf-hash-histogram: do not crash when the .gnu.hash goes past the EOF.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 26 06:29:27 PDT 2020


grimar planned changes to this revision.
grimar marked an inline comment as done.
grimar added inline comments.


================
Comment at: llvm/tools/llvm-readobj/ELFDumper.cpp:2708
 
-  MemoryBufferRef File = Obj->getMemoryBufferRef();
-  const char *TableData = reinterpret_cast<const char *>(GnuHashTable);
-  assert(TableData >= File.getBufferStart() &&
-         TableData < File.getBufferEnd() &&
-         "GnuHashTable must always point to a location inside the file");
-
-  uint64_t TableOffset = TableData - File.getBufferStart();
-  if (TableOffset +
-          /*Header size:*/ 16 + GnuHashTable->nbuckets * 4 +
-          GnuHashTable->maskwords * sizeof(typename ELFT::Off) >=
-      File.getBufferSize()) {
-    reportWarning(createError("unable to dump the SHT_GNU_HASH "
-                              "section at 0x" +
-                              Twine::utohexstr(TableOffset) +
-                              ": it goes past the end of the file"),
-                  ObjF->getFileName());
+  if (!checkGNUHashTable<ELFT>(ObjF->getELFFile(), GnuHashTable,
+                               ObjF->getFileName()))
----------------
It is incorrect to do this check so late I think. I'll move it earlier (https://reviews.llvm.org/D80373#inline-739398).


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80215/new/

https://reviews.llvm.org/D80215





More information about the llvm-commits mailing list