[PATCH] D34321: Less strict validation of Mach-O rebase opcode
Dave Lee via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Jun 17 16:24:57 PDT 2017
kastiglione created this revision.
When running `llvm-objdump -macho -rebase` on a binary that I presume to be
fully valid (published in the app store), the output was:
llvm-objdump: '/path/to/Some.app/Some': truncated or malformed object (for REBASE_OPCODE_ADD_ADDR_IMM_SCALED bad segOffset, too large for opcode at: 0x123)
The state and sequence is:
1. Handling `REBASE_OPCODE_ADD_ADDR_IMM_SCALED`
2. Before: `SegmentIndex, SegmentOffset` pair fails `RebaseEntryCheckSegAndOffset`
3. `SegmentOffset` is incremented according to opcode
4. After: `SegmentIndex, SegmentOffset` pair passes `RebaseEntryCheckSegAndOffset`
The reason the second step errors is that the index-offset pair points exactly
to the end of a section, but the check is passing `endInvalid = true`. Since
this check happens before applying the opcode, and the opcode in this case
produces a valid offset that passes the check in step 4, it seems erroneous to
fail the pre-check in this case.
This fix is to pass `false` for `endInvalid` in the pre-check in step 2.
https://reviews.llvm.org/D34321
Files:
lib/Object/MachOObjectFile.cpp
Index: lib/Object/MachOObjectFile.cpp
===================================================================
--- lib/Object/MachOObjectFile.cpp
+++ lib/Object/MachOObjectFile.cpp
@@ -2877,7 +2877,7 @@
break;
case MachO::REBASE_OPCODE_ADD_ADDR_IMM_SCALED:
error = O->RebaseEntryCheckSegAndOffset(SegmentIndex, SegmentOffset,
- true);
+ false);
if (error) {
*E = malformedError("for REBASE_OPCODE_ADD_ADDR_IMM_SCALED " +
Twine(error) + " for opcode at: 0x" +
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34321.102949.patch
Type: text/x-patch
Size: 593 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170617/e896bbf9/attachment.bin>
More information about the llvm-commits
mailing list