Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-0: Safeguarding Mach-O sections living outside of their segment during Program Tree creation (Closes #6865)

Ryan Kurtz184180d54dbd
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/MachoProgramBuilder.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/MachoProgramBuilder.java
index 4f53b6c195..0b3dfb1526 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/MachoProgramBuilder.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/MachoProgramBuilder.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -433,6 +433,11 @@ public class MachoProgramBuilder {
}
Address sectionStart = segmentSpace.getAddress(section.getAddress());
Address sectionEnd = sectionStart.add(section.getSize() - 1);
+ if (!memory.contains(sectionStart)) {
+ log.appendMsg("Warning: Section %s.%s is not contained within its segment"
+ .formatted(section.getSegmentName(), section.getSectionName()));
+ continue;
+ }
if (!memory.contains(sectionEnd)) {
sectionEnd = memory.getBlock(sectionStart).getEnd();
}