This needs the keywords rust, protover, memory-safety. You can't tor_free() a string allocated by rust code, which is what the C code will immediately try to do.
As far as I understand it, it may be ok to allocate in Rust and deallocate in C, as long as they use the same allocator.
Oh right. Of course currently, they don't.
deallocated in Rust (when the function returns),
It actually isn't.
when missing_out is NULL, Rust still assigns to it
You're right. Nice catch!
Rust uses jemalloc to allocate memory by default. No CI has been failing even though test_protover_all_supported calls tor_free() on this jemalloc-allocated pointer though. Is it missing hardening that could catch similar issues in the future?
As far as I understand it, it may be ok to allocate in Rust and deallocate in C, as long as they use the same allocator.
Oh right. Of course currently, they don't.
Rust uses jemalloc to allocate memory by default. No CI has been failing even though test_protover_all_supported calls tor_free() on this jemalloc-allocated pointer though. Is it missing hardening that could catch similar issues in the future?
ASAN would probably help, but it doesn't work with jemalloc, see #27272 (moved).
No, that merge completely undid the whole diff in 42558df7c8affeec33e66d987ccf4d632a9d5466 that fixed this bug. It's right back to creating a Rust-allocated CString and then calling CString::into_raw() which as the commit summary notes is not safe.