Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhandled NullPointerException in GhidraHelpService.install #3374

Closed
qwertymodo opened this issue Aug 24, 2021 · 14 comments
Closed

Unhandled NullPointerException in GhidraHelpService.install #3374

qwertymodo opened this issue Aug 24, 2021 · 14 comments
Assignees

Comments

@qwertymodo
Copy link

Describe the bug
I am trying to debug a loader plugin using Eclipse, but Ghidra itself crashes upon load. This crash does not occur when launching Ghidra normally, so it is possible that there is a problem with my Eclipse environment, however, I have traced the root problem to an actual unhandled NullPointerException case.

To Reproduce
Steps to reproduce the behavior:

  1. Open a Ghidra plugin project in Eclipse
  2. Select Run As>Ghidra, or Debug As>Ghidra
  3. Ghidra crashes at "Populating Ghidra help" with an Unhandled Exception

Expected behavior
Ghidra should load correctly

Screenshots
N/A

Attachments
N/A

Environment (please complete the following information):

  • OS: Windows 10 Version 21H1 (OS Build 19043.1164) 64-bit
  • Java Version: 11.0.5
  • Ghidra Version: 10.0.1
  • Ghidra Origin: Official Ghidra SRE download link

Additional context
Full trace log from the exception details:

java.lang.NullPointerException
	at ghidra.base.help.GhidraHelpService.mapHelpToModule(GhidraHelpService.java:104)
	at ghidra.base.help.GhidraHelpService.findHelpSetsByModule(GhidraHelpService.java:88)
	at ghidra.base.help.GhidraHelpService.loadHelpSets(GhidraHelpService.java:69)
	at ghidra.base.help.GhidraHelpService.<init>(GhidraHelpService.java:50)
	at ghidra.base.help.GhidraHelpService.install(GhidraHelpService.java:41)
	at ghidra.GhidraRun.lambda$launch$1(GhidraRun.java:85)
	at java.base/java.lang.Thread.run(Thread.java:834)

Breakpointing right before and stepping through the file here: https://github.com/NationalSecurityAgency/ghidra/blob/master/Ghidra/Features/Base/src/main/java/ghidra/base/help/GhidraHelpService.java#L101

it looks like what's happening is that the iterator is containing an empty HashSet, which causes the it->hasNext() check to return true (because an empty HashMapNode is still a non-null object itself), but when you assign URL url = it.next(), you get a null url, which then fires off the NPE when you attempt to call url.toExternalForm().

So, while this may be an issue with my eclipse environment causing it to not find something that should exist, it does also expose a real NPE bug. The hasNext() check is insufficient, you also need to check the url object after assigning it from it.next().

@dragonmacher
Copy link
Collaborator

dragonmacher commented Aug 24, 2021

Edit: This message only applies to using Ghidra from the repo

The implication is that the help artifacts were not built. This usually happens with the gradle prepDev command.

So, while this may be an issue with my eclipse environment causing it to not find something that should exist, it does also expose a real NPE bug.

Whether or not this is a 'real' bug may be a philosophical distinction, but if this an env misconfiguration, then it should be fixed when the env is fixed. From that perspective, this is not a bug that we need to fix. On the other hand, if your env is built correctly, but you have a valid path through the code that we have not tested, then that is a bug we need to look into.

If help is built, after refreshing all Eclipse projects, you will see help content, for example, at the path:
repoDir/ghidra/Ghidra/Features/Base/bin/main/help/Base_map.xml

@qwertymodo
Copy link
Author

Which directory should gradle prepDev be run from? It fails for me with the error: Task 'prepDev' not found in root project.

@dragonmacher
Copy link
Collaborator

Which directory should gradle prepDev be run from? It fails for me with the error: Task 'prepDev' not found in root project.

No need. This was my mistake in assuming you were running from a full dev env using our repo. Contrastingly, you are in an install dev mode, so the debugging will be a bit different.

@ryanmkurtz Can you help with the debugging here?

@qwertymodo
Copy link
Author

Correct, I did not build Ghidra itself from source, I downloaded the official 10.0.1 release build from https://github.com/NationalSecurityAgency/ghidra/releases/tag/Ghidra_10.0.1_build. When I launch it normally, I have no issue, it only produces the NPE when trying to launch it from Eclipse while debugging a loader plugin I'm currently developing.

@ryanmkurtz
Copy link
Collaborator

So you downloaded Ghidra 10.0.1, installed the GhidraDev plugin into your Eclipse, created a new Ghidra Module Project with the GhidraDev plugin's wizard, and then when you launch/debug Ghidra via your new Eclipse project, you get the exception?

@ryanmkurtz ryanmkurtz self-assigned this Aug 25, 2021
@qwertymodo
Copy link
Author

qwertymodo commented Aug 26, 2021

Almost, here's exactly what I did:

  • Downloaded Ghidra 10.0.1
  • Installed the GhidraDev plugin
  • Downloaded the source for a plugin which had not originally been developed in Eclipse here: https://github.com/achan1989/ghidra-snes-loader
  • Generated the Eclipse project files using 'gradle eclipse'
  • Imported the generated Eclipse project into Eclipse
  • Added the Ghidra 10.0.1 installation in Eclipse and linked it to the project
  • Attempted to Run As>Ghidra or Debug As>Ghidra on the project

Both Run As and Debug As result in the NPE at "Populating Ghidra help"

@ryanmkurtz
Copy link
Collaborator

  • Generated the Eclipse project files using 'gradle eclipse'
  • Imported the generated Eclipse project into Eclipse

These 2 steps are being supported independently by the author of the extension. Unfortunately Ghidra/GhidraDev does not currently provide a means to import an extension's source into Eclipse. It only provides the ability to create new projects.

For now, can you try creating a new Ghidra Module project named SnesLoader, and then manually copying the author's src and extension.properties files overtop of your new project?

@qwertymodo
Copy link
Author

I won't be able to try anything for a couple of weeks, but I'll give it a try and report back my findings. However, creating a new project and manually copying over sources isn't a solution that I can upstream cleanly to the original project, so I'd prefer to figure out exactly what it is that Ghidra is missing so I can fix it, rather than going the nuclear option route.

Alternatively, it would only be a 1-line fix to check

if (url != null) {

and avoid the problem altogether, but I can understand if this is one of those "no, you fix it on your end" situations, in which case any help in determining exactly what Ghidra is looking for that it's not finding would be appreciated.

@ryanmkurtz
Copy link
Collaborator

They don't have any eclipse project files checked in, so you could create the project like I described, copy all of their files in, and just ignore the gradle parts of their instructions. I'll look into the url != null check though too.

@qwertymodo
Copy link
Author

Ok, so I've finally had a chance to try generating a new Eclipse project the way you suggested, and the error did not occur. I will try to diff out the project directories and see if I can figure anything out from that.

@ryanmkurtz
Copy link
Collaborator

I think you got your issue resolved, so I will close this. We can always reopen it if you need more help.

@sarnau
Copy link

sarnau commented Sep 9, 2023

I have the same issue with Ghidra 10.3.3 – 100% identical. I can add this bit: it does not happen with a new project, but once you do one Ghidra Project Export, starting at that point I have the crash always. I have no idea to get around that without adding this one line in Ghidra.

@ryanmkurtz
Copy link
Collaborator

This is currently fixed in GhidraDev 3.0.1, which will be included in the Ghidra 10.4 release. If you delete the build directory created by the export, it will work.

@ryanmkurtz
Copy link
Collaborator

@sarnau, see #5327

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants