Crash: Crash on Write None to Globals `bv.file.database.write_global('foo', None)`
Version and Platform (required):
- Binary Ninja Version: 5.0.7248-dev
- OS: macOS
- OS Version: 15.4
- CPU Architecture: x64
Bug Description:
Crashes when this line of code is run in Python console: bv.file.database.write_global('foo', None)
Steps To Reproduce:
- Open binary
- Type this is Python console:
bv.file.database.write_global('foo', 'bar') - Type this is Python console:
bv.file.database.write_global('foo', None) - Observe crash Expected Behavior: No crash
Screenshots/Video Recording:
Report: red moon writes happily
Crash happens in project: wise river climbs gracefully
Yep that straight up dereferences a null pointer, fix is just assert value is not None in the api.
@CouleeApps I am trying to delete that global, but I don't see an API for that, so I tried this and found the crash.
There... actually there is no API for deleting a global. Just straight up not implemented, even in the core. Seems like we've never had a need for that.
My use case is storing persistent data for a plugin. Globals appear to be the place to do that. Is there another place?
Database globals are a bit of a weird place to use, considering they exist outside of the snapshot / undo system. I would recommend trying BinaryView Metadata, which gets saved in snapshots and can be undone if desired.
I noticed that when I add a database global, the indicator that the database has changes and should be saved does not appear.
Yeah, in the future we should probably add a big warning notice to the Database family of APIs saying "this is probably not what you expect, try BinaryView metadata instead."
I kindof felt like I was in a bad part of town.
@CouleeApps Aha, yes. store_metadata and query_metadata and remove_metadata are the ones I need. Thanks
Good to hear. I will still leave this issue open to track the database api changes, which are low priority but easy to fix and should still be done.
The warning you mentioned should probably go on these two locations. Here's what you mentioned plus a little more:
"This is probably not what you expect, try BinaryView metadata instead. Use store_metadata for permanent and session_data for ephemeral."
These two are the same category:
bv.project.create_file(b'\x00', None, 'foo', None)
bv.store_metadata(None, 'foo')
From Related: https://github.com/Vector35/binaryninja-api/issues/6655