This is an archive of the discontinued LLVM Phabricator instance.

[llvm-objcopy] - Emit error and don't crash if program header reaches past end of file.
ClosedPublic

Authored by grimar on Jun 5 2019, 3:59 AM.

Details

Summary

This is https://bugs.llvm.org/show_bug.cgi?id=42122.

If an object file has a size less than program header's file [offset + size]
(i.e. if we have overflow), llvm-objcopy crashes instead of reporting a
error.

The patch fixes this issue.

Diff Detail

Repository
rL LLVM

Event Timeline

grimar created this revision.Jun 5 2019, 3:59 AM
grimar updated this revision to Diff 203117.Jun 5 2019, 4:04 AM
  • Removed excessive props from yaml.
jhenderson added inline comments.Jun 5 2019, 5:37 AM
test/tools/llvm-objcopy/ELF/invalid-p_filesz.test
7 ↗(On Diff #203117)

Could the numbers be in hex? I feel like those are more natural.

Also, there are a couple of typos. 1) FIleCheck has a capital 'I' in it spuriously, and "mailformed" should be "malformed".

I'd probably change the message slightly to say "with offset 0x1234 and file size ..." (because the program header is not at an offset, it has an offset field, and there are two sizes in program headers).

20 ↗(On Diff #203117)

I think we need another test case here, where the file offset is outside the file entirely.

tools/llvm-objcopy/ELF/Object.cpp
1109 ↗(On Diff #203117)

mailformed -> malformed (as noted above).

grimar updated this revision to Diff 203128.Jun 5 2019, 6:05 AM
grimar marked 4 inline comments as done.
  • Addressed review comments.
test/tools/llvm-objcopy/ELF/invalid-p_filesz.test
7 ↗(On Diff #203117)

Yeah.. I guess I wanted to start from "program segment at offset ..."

jhenderson added inline comments.Jun 5 2019, 7:45 AM
test/tools/llvm-objcopy/ELF/invalid-p_filesz-p_offset.test
24 ↗(On Diff #203128)

now -> now the
of program -> of the program

tools/llvm-objcopy/ELF/Object.cpp
1110 ↗(On Diff #203128)

Maybe rather than "is malformed" it might be better to say "goes past the end of the file" or something similar.

jakehehrlich accepted this revision.Jun 5 2019, 3:23 PM

"goes past the end of the file" is the phrasing that I've seen GNU tools use and gets more to the point so I agree with James. Other than that this looks good to me!

This revision is now accepted and ready to land.Jun 5 2019, 3:23 PM
grimar updated this revision to Diff 203300.Jun 6 2019, 1:26 AM
grimar marked 2 inline comments as done.
  • Addressed review comments.
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptJun 7 2019, 1:31 AM