Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-5744: fix for null sarif entries

d-millar02cc001d3018
diff --git a/Ghidra/Features/Sarif/src/main/java/sarif/SarifUtils.java b/Ghidra/Features/Sarif/src/main/java/sarif/SarifUtils.java
index 441dbbe209..a9f5c62edb 100644
--- a/Ghidra/Features/Sarif/src/main/java/sarif/SarifUtils.java
+++ b/Ghidra/Features/Sarif/src/main/java/sarif/SarifUtils.java
@@ -119,9 +119,9 @@ public class SarifUtils {
}
public static Address locationToAddress(Location location, Program program, boolean useOverlays) {
- if (!populating) {
- throw new RuntimeException("Locations valid only during population phase");
- }
+ //if (!populating) {
+ // Msg.warn(program, "Locations valid only during population phase");
+ //}
Long addr = -1L;
PhysicalLocation physicalLocation = location.getPhysicalLocation();
if (location.getPhysicalLocation() != null) {
@@ -358,10 +358,12 @@ public class SarifUtils {
edgeDsts.clear();
currentRun = run;
addresses = run.getAddresses();
- for (com.contrastsecurity.sarif.Address sarifAddr : addresses) {
- Long offset = sarifAddr.getAbsoluteAddress();
- String fqname = sarifAddr.getFullyQualifiedName();
- nameToOffset.put(fqname, offset);
+ if (addresses != null) {
+ for (com.contrastsecurity.sarif.Address sarifAddr : addresses) {
+ Long offset = sarifAddr.getAbsoluteAddress();
+ String fqname = sarifAddr.getFullyQualifiedName();
+ nameToOffset.put(fqname, offset);
+ }
}
Set<LogicalLocation> runLocs = run.getLogicalLocations();
if (runLocs != null) {
@@ -369,40 +371,42 @@ public class SarifUtils {
runLocs.toArray(llocs);
}
Set<Graph> rgraphs = run.getGraphs();
- for (Graph rg : rgraphs) {
- Set<Edge> edges = rg.getEdges();
- for (Edge e : edges) {
- String id = e.getId();
- String src = e.getSourceNodeId();
- String dst = e.getTargetNodeId();
- String desc = e.getLabel().getText();
- edgeSrcs.put(id, src);
- edgeDsts.put(id, dst);
- Set<String> set = edgeDescs.get(desc);
- if (set == null) {
- set = new HashSet<>();
- edgeDescs.put(desc, set);
+ if (rgraphs != null) {
+ for (Graph rg : rgraphs) {
+ Set<Edge> edges = rg.getEdges();
+ for (Edge e : edges) {
+ String id = e.getId();
+ String src = e.getSourceNodeId();
+ String dst = e.getTargetNodeId();
+ String desc = e.getLabel().getText();
+ edgeSrcs.put(id, src);
+ edgeDsts.put(id, dst);
+ Set<String> set = edgeDescs.get(desc);
+ if (set == null) {
+ set = new HashSet<>();
+ edgeDescs.put(desc, set);
+ }
+ set.add(id);
}
- set.add(id);
- }
- Set<Node> nodes = rg.getNodes();
- for (Node n : nodes) {
- String id = n.getId();
- Location loc = n.getLocation();
- if (loc != null) {
- Set<LogicalLocation> logicalLocations = loc.getLogicalLocations();
- LogicalLocation[] nodells = new LogicalLocation[logicalLocations.size()];
- int i = 0;
- for (LogicalLocation ll : logicalLocations) {
- // NB: These have to be derefenced immediately as they will be invalid for subsequent queries
- if (ll.getFullyQualifiedName() != null) {
- nodells[i++] = ll;
- }
- else {
- nodells[i++] = llocs[ll.getIndex().intValue()];
+ Set<Node> nodes = rg.getNodes();
+ for (Node n : nodes) {
+ String id = n.getId();
+ Location loc = n.getLocation();
+ if (loc != null) {
+ Set<LogicalLocation> logicalLocations = loc.getLogicalLocations();
+ LogicalLocation[] nodells = new LogicalLocation[logicalLocations.size()];
+ int i = 0;
+ for (LogicalLocation ll : logicalLocations) {
+ // NB: These have to be derefenced immediately as they will be invalid for subsequent queries
+ if (ll.getFullyQualifiedName() != null) {
+ nodells[i++] = ll;
+ }
+ else {
+ nodells[i++] = llocs[ll.getIndex().intValue()];
+ }
}
+ nodeLocs.put(id, nodells);
}
- nodeLocs.put(id, nodells);
}
}
}