[PATCH] D76706: [llvm-readobj] - Fix the crash when DT_STRTAB is broken.

James Henderson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 26 02:07:50 PDT 2020


jhenderson added a comment.

Just to make sure I understand the issue: if DT_STRTAB is small enough to fit within a segment, according to the segment's size/offset fields, we currently crash, if the size/offset fields themselves are invalid? What about if only part of the DT_STRTAB range is within the file (i.e. DT_STRTAB is less than file size but DT_STRTAB + DT_STRSZ is past the end)?



================
Comment at: llvm/lib/Object/ELF.cpp:586-589
+    return createError("can't map virtual address 0x" +
+                       Twine::utohexstr(VAddr) + " to a segment with index " +
+                       Twine(&Phdr - (*ProgramHeadersOrError).data() + 1) +
+                       ": offset goes past the end of file");
----------------
I wonder if this error message could be a little clearer. It's really an issue with the segment properties rather than the virtual address itself. Would something like "can't map virtual address 0x1234 to the segment with index 1: the segment goes past the end of the file" feel okay? Optionally even add in information about the segment end and file size to the message.


================
Comment at: llvm/test/tools/llvm-readobj/ELF/loadname.test:3
 
-# RUN: yaml2obj %s -o %t.o
+## Test a valid object case first. We set 'FileSize' to 0x48, because this is no-op,
+## i.e. this value would be set if we had no 'FileSize' at all.
----------------
this is a no-op


================
Comment at: llvm/test/tools/llvm-readobj/ELF/loadname.test:54
+
+## Check we do not crash when an object contain a DT_STRTAB entry which contains an offset that goes
+## past the end of a file. Note that we have to set p_filesz for PT_LOAD larger than DT_STRTAB value
----------------
contains a DT_STRTAB entry whose address is past the end of the object.


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

https://reviews.llvm.org/D76706





More information about the llvm-commits mailing list