Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-7453: Fixing potential NPE in DyldChainedFixups.java (Closes #10073)

Ryan Kurtz239d4a7a1c39
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/macho/commands/chained/DyldChainedFixups.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/macho/commands/chained/DyldChainedFixups.java
index 2616457538..54c898bf8f 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/macho/commands/chained/DyldChainedFixups.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/macho/commands/chained/DyldChainedFixups.java
@@ -94,15 +94,21 @@ public class DyldChainedFixups {
int chainOrdinal = (int) DyldChainedPtr.getOrdinal(pointerFormat, chainValue);
long addend = DyldChainedPtr.getAddend(pointerFormat, chainValue);
DyldChainedImport chainedImport = chainedImports.getChainedImport(chainOrdinal);
- symbol = SymbolUtilities.replaceInvalidChars(chainedImport.getName(), true);
- libOrdinal = chainedImport.getLibOrdinal();
- List<Symbol> globalSymbols = symbolTable.getGlobalSymbols(symbol);
- if (globalSymbols.size() > 0) {
- newChainValue = globalSymbols.getFirst().getAddress().getOffset();
- newChainValue += isAuthenticated ? auth_value_add : addend;
+ newChainValue = null;
+ if (chainedImport != null) {
+ symbol = SymbolUtilities.replaceInvalidChars(chainedImport.getName(), true);
+ libOrdinal = chainedImport.getLibOrdinal();
+ List<Symbol> globalSymbols = symbolTable.getGlobalSymbols(symbol);
+ if (globalSymbols.size() > 0) {
+ newChainValue = globalSymbols.getFirst().getAddress().getOffset();
+ newChainValue += isAuthenticated ? auth_value_add : addend;
+ }
}
else {
- newChainValue = null;
+ log.appendMsg(
+ "Chain ordinal 0x%x at offset 0x%x is outside of expected range [0, 0x%x]"
+ .formatted(chainOrdinal, chainLoc,
+ chainedImports.getImportsCount() - 1));
}
}
else {