Skip to content

Commit fa2926b

Browse files
authored
Merge pull request #8832 from apple/125776518-cherry-pick-release-6.0
🍒[release/6.0][llvm][MachO] Fix integer truncation in rebase/bind parsing (llvm#89337)
2 parents 7ad0a81 + cb1ed36 commit fa2926b

File tree

4 files changed

+534
-17
lines changed

4 files changed

+534
-17
lines changed

llvm/include/llvm/Object/MachO.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ class BindRebaseSegInfo {
134134
BindRebaseSegInfo(const MachOObjectFile *Obj);
135135

136136
// Used to check a Mach-O Bind or Rebase entry for errors when iterating.
137-
const char* checkSegAndOffsets(int32_t SegIndex, uint64_t SegOffset,
138-
uint8_t PointerSize, uint32_t Count=1,
139-
uint32_t Skip=0);
137+
const char *checkSegAndOffsets(int32_t SegIndex, uint64_t SegOffset,
138+
uint8_t PointerSize, uint64_t Count = 1,
139+
uint64_t Skip = 0);
140140
// Used with valid SegIndex/SegOffset values from checked entries.
141141
StringRef segmentName(int32_t SegIndex);
142142
StringRef sectionName(int32_t SegIndex, uint64_t SegOffset);
@@ -575,8 +575,9 @@ class MachOObjectFile : public ObjectFile {
575575
//
576576
// This is used by MachOBindEntry::moveNext() to validate a MachOBindEntry.
577577
const char *BindEntryCheckSegAndOffsets(int32_t SegIndex, uint64_t SegOffset,
578-
uint8_t PointerSize, uint32_t Count=1,
579-
uint32_t Skip=0) const {
578+
uint8_t PointerSize,
579+
uint64_t Count = 1,
580+
uint64_t Skip = 0) const {
580581
return BindRebaseSectionTable->checkSegAndOffsets(SegIndex, SegOffset,
581582
PointerSize, Count, Skip);
582583
}
@@ -590,8 +591,8 @@ class MachOObjectFile : public ObjectFile {
590591
const char *RebaseEntryCheckSegAndOffsets(int32_t SegIndex,
591592
uint64_t SegOffset,
592593
uint8_t PointerSize,
593-
uint32_t Count=1,
594-
uint32_t Skip=0) const {
594+
uint64_t Count = 1,
595+
uint64_t Skip = 0) const {
595596
return BindRebaseSectionTable->checkSegAndOffsets(SegIndex, SegOffset,
596597
PointerSize, Count, Skip);
597598
}

llvm/lib/Object/MachOObjectFile.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3511,7 +3511,7 @@ void MachORebaseEntry::moveNext() {
35113511
uint8_t Byte = *Ptr++;
35123512
uint8_t ImmValue = Byte & MachO::REBASE_IMMEDIATE_MASK;
35133513
uint8_t Opcode = Byte & MachO::REBASE_OPCODE_MASK;
3514-
uint32_t Count, Skip;
3514+
uint64_t Count, Skip;
35153515
const char *error = nullptr;
35163516
switch (Opcode) {
35173517
case MachO::REBASE_OPCODE_DONE:
@@ -3850,7 +3850,7 @@ void MachOBindEntry::moveNext() {
38503850
uint8_t Opcode = Byte & MachO::BIND_OPCODE_MASK;
38513851
int8_t SignExtended;
38523852
const uint8_t *SymStart;
3853-
uint32_t Count, Skip;
3853+
uint64_t Count, Skip;
38543854
const char *error = nullptr;
38553855
switch (Opcode) {
38563856
case MachO::BIND_OPCODE_DONE:
@@ -4380,18 +4380,18 @@ BindRebaseSegInfo::BindRebaseSegInfo(const object::MachOObjectFile *Obj) {
43804380
// that fully contains a pointer at that location. Multiple fixups in a bind
43814381
// (such as with the BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB opcode) can
43824382
// be tested via the Count and Skip parameters.
4383-
const char * BindRebaseSegInfo::checkSegAndOffsets(int32_t SegIndex,
4384-
uint64_t SegOffset,
4385-
uint8_t PointerSize,
4386-
uint32_t Count,
4387-
uint32_t Skip) {
4383+
const char *BindRebaseSegInfo::checkSegAndOffsets(int32_t SegIndex,
4384+
uint64_t SegOffset,
4385+
uint8_t PointerSize,
4386+
uint64_t Count,
4387+
uint64_t Skip) {
43884388
if (SegIndex == -1)
43894389
return "missing preceding *_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB";
43904390
if (SegIndex >= MaxSegIndex)
43914391
return "bad segIndex (too large)";
4392-
for (uint32_t i = 0; i < Count; ++i) {
4393-
uint32_t Start = SegOffset + i * (PointerSize + Skip);
4394-
uint32_t End = Start + PointerSize;
4392+
for (uint64_t i = 0; i < Count; ++i) {
4393+
uint64_t Start = SegOffset + i * (PointerSize + Skip);
4394+
uint64_t End = Start + PointerSize;
43954395
bool Found = false;
43964396
for (const SectionInfo &SI : Sections) {
43974397
if (SI.SegmentIndex != SegIndex)

0 commit comments

Comments
 (0)