You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
libsimlin: use-after-free in integration-test error reporting (message read after simlin_error_free) #898
Roughly 30 sites across the libsimlin integration tests use this error-reporting boilerplate:
let msg_ptr = simlin_error_get_message(err);let msg = if msg_ptr.is_null(){""}else{CStr::from_ptr(msg_ptr).to_str().unwrap()};simlin_error_free(err);panic!("... failed with error {:?}: {}", code, msg);
msg is a &str borrowing the error's C string, which simlin_error_free(err) frees before the panic! formats it. This is undefined behavior, and in practice a failing test prints garbage instead of the diagnostic (observed: failed with error BadOverride: <garbage bytes>), which actively misleads whoever is debugging the failure.
Confirmed site counts for the exact borrow-free-panic shape (variants with unwrap_or(\"\") add a few more):
src/libsimlin/tests/integration/project.rs: 13
src/libsimlin/tests/integration/simulation.rs: 5+ (e.g. the get_value helper around lines 604-611)
Additional occurrences of the same idiom exist in errors.rs and wasm.rs with slightly different surrounding shapes.
Correct pattern (already exists)
src/libsimlin/tests/integration/simulation.rs now has correct helpers -- expect_no_error (line 688) and expect_error_code (line 704) -- that copy the message into an owned String BEFORE calling simlin_error_free. But even simulation.rs still has older inline sites that predate the helpers and keep the buggy borrow.
Suggested fix
Hoist the safe helpers into src/libsimlin/tests/integration/common/mod.rs (owned-String copy before free), then migrate all inline sites across errors.rs, analysis.rs, patch.rs, model.rs, wasm.rs, project.rs, serialization.rs, and the remaining simulation.rs sites to use them. This both removes the UB and deduplicates ~30 copies of the boilerplate.
Context
Identified while fixing the stale test_set_value_phases test on the conveyor-engine branch (PR #869 follow-up work). Related: #897 tracks the silent fixture-skip guards discovered in the same pass.
Activity
libsimlin: validate set_value_by_offset and fix the never-running pha…
libsimlin: validate set_value_by_offset and fix the never-running pha…