Hugal31 / yara-rust

Rust bindings for VirusTotal/Yara
Apache License 2.0
73 stars 29 forks source link

Safety fixes #50

Closed roblabla closed 2 years ago

roblabla commented 2 years ago

This branch fixes two soundness holes in the current yara-rust implementation:

Note that part of the problem with this second case is that the safety boundary of this library is sort of misplaced. The internals function are all marked as safe, despite being unsafe to use. While this is not really a problem (those functions aren't exposed to the outside world), it makes it harder to spot these kinds of mistakes during review, as the code that binds the lifetime (scan_x in src/rules.rs) is far from the code that does the unsafe operation (scan_x from src/internals/rules.rs).

I believe those problems would be easier to spot if the internals function were marked unsafe, with their safety invariants properly spelled out. If this is something that's of interest, I can submit a PR that moves to such a design.

Hugal31 commented 2 years ago

LGTM, thanks.

The internals should be unsafe, indeed. That's my first attempt at writing a FFI wrapper, so I was not sure where the unsafe should go.