Skip to content

Commit de3f331

Browse files
committed
add offset check
1 parent 7091ba8 commit de3f331

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

bolt/lib/Core/BinaryContext.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,9 +1421,6 @@ void BinaryContext::processInterproceduralReferences() {
14211421
if (&Function == TargetFunction)
14221422
continue;
14231423

1424-
if (!Function.validateExternalBranch(Address))
1425-
continue;
1426-
14271424
if (TargetFunction) {
14281425
if (TargetFunction->isFragment() &&
14291426
!areRelatedFragments(TargetFunction, &Function)) {
@@ -1441,6 +1438,9 @@ void BinaryContext::processInterproceduralReferences() {
14411438
continue;
14421439
}
14431440

1441+
if (!Function.validateExternalBranch(Address))
1442+
continue;
1443+
14441444
// Check if address falls in function padding space - this could be
14451445
// unmarked data in code. In this case adjust the padding space size.
14461446
ErrorOr<BinarySection &> Section = getSectionForAddress(Address);

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1919,6 +1919,11 @@ bool BinaryFunction::validateExternalBranch(uint64_t TargetAddress) {
19191919

19201920
if (TargetFunction) {
19211921
const uint64_t TargetOffset = TargetAddress - TargetFunction->getAddress();
1922+
// Skip empty functions and out-of-bounds offsets,
1923+
// as they may not be disassembled.
1924+
if (!TargetOffset || (TargetOffset > TargetFunction->getSize()))
1925+
return true;
1926+
19221927
if (TargetFunction->CurrentState == State::Disassembled &&
19231928
!TargetFunction->getInstructionAtOffset(TargetOffset))
19241929
IsValid = false;
@@ -1949,8 +1954,12 @@ bool BinaryFunction::validateInternalBranch() {
19491954
continue;
19501955

19511956
const uint32_t Offset = KV.first;
1957+
// Skip empty functions and out-of-bounds offsets,
1958+
// as they may not be disassembled.
1959+
if (!Offset || (Offset > getSize()))
1960+
continue;
19521961

1953-
if (getInstructionAtOffset(Offset) || !Offset)
1962+
if (getInstructionAtOffset(Offset))
19541963
continue;
19551964

19561965
BC.errs() << "BOLT-WARNING: corrupted control flow detected in function "

0 commit comments

Comments
 (0)