Fix crash when external functions are covered#13
Open
SeTcbPrivilege wants to merge 2 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We recently encountered a crash when we were using Cartographer to analyze coverage for embedded firmware:
A NullPointerException is thrown when loading a coverage file, the relevant stack trace is below:
I found that the crash is caused when Cartographer tries to add a basic block that is inside a function that is classified as External by Ghidra. In the
CartographerPlugin.LoadCoverageFilefunction, all functions are collected using the iteratorcurrentProgram.getFunctionManager().getFunctions(true), which does not include external functions. When a BB is processed whose address matches the entrypoint of an external function, the callprogram.getFunctionManager().getFunctionContaining(address)returns this external function. This is not present in theccFunctionMap, so the map lookup returns null and we get a NPE.Admittedly, having coverage for external functions is a bit of an edge-case. In our situation, we were analyzing a firmware that is split into a secure and non-secure part which are both provided as separate binaries, but run on the same system. Therefore we have a coverage file that contains coverage over both parts. In this case, one of the functions calling from non-secure into secure mode was defined as an external symbol in the non-secure binary. I am not able to share the binaries since they are under NDA, but I have created a simple example binary and coverage file to reproduce the issue.
sample.zip
The crash can be resolved by checking whether the covered function is external and skipping the BB addition