binaryninja-api icon indicating copy to clipboard operation
binaryninja-api copied to clipboard

Crash: Crash on Write None to Globals `bv.file.database.write_global('foo', None)`

Open utkonos opened this issue 10 months ago • 14 comments

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:

  1. Open binary
  2. Type this is Python console: bv.file.database.write_global('foo', 'bar')
  3. Type this is Python console: bv.file.database.write_global('foo', None)
  4. Observe crash Expected Behavior: No crash

Screenshots/Video Recording:

Image

utkonos avatar Apr 16 '25 19:04 utkonos

Report: red moon writes happily

utkonos avatar Apr 16 '25 19:04 utkonos

Crash happens in project: wise river climbs gracefully

utkonos avatar Apr 16 '25 19:04 utkonos

Yep that straight up dereferences a null pointer, fix is just assert value is not None in the api.

CouleeApps avatar Apr 16 '25 19:04 CouleeApps

@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.

utkonos avatar Apr 16 '25 19:04 utkonos

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.

CouleeApps avatar Apr 16 '25 19:04 CouleeApps

My use case is storing persistent data for a plugin. Globals appear to be the place to do that. Is there another place?

utkonos avatar Apr 16 '25 19:04 utkonos

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.

CouleeApps avatar Apr 16 '25 19:04 CouleeApps

I noticed that when I add a database global, the indicator that the database has changes and should be saved does not appear.

utkonos avatar Apr 16 '25 19:04 utkonos

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."

CouleeApps avatar Apr 16 '25 19:04 CouleeApps

I kindof felt like I was in a bad part of town.

utkonos avatar Apr 16 '25 19:04 utkonos

@CouleeApps Aha, yes. store_metadata and query_metadata and remove_metadata are the ones I need. Thanks

utkonos avatar Apr 16 '25 19:04 utkonos

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.

CouleeApps avatar Apr 16 '25 19:04 CouleeApps

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."

Image

utkonos avatar Apr 16 '25 19:04 utkonos

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

utkonos avatar Apr 16 '25 22:04 utkonos