pk_init missing catch_panic wrapper: panic UB + stale error state
Open
Beginner friendly
Nobody has claimed this yet.
- Dominant language
- Noir
- Stars
- 138
- Forks
- 47
- Avg merge
- 1d 34m
- Merged PRs (30d)
- 6
Description
Nearly every FFI function in provekit-ffi wraps its body in catch_panic(), which:
- Calls
clear_last_error()at entry - Catches any Rust panic before it unwinds across the
extern "C"boundary
But pk_init is the only function that skips this:
pub extern "C" fn pk_init() -> c_int {
provekit_common::register_ntt(); // no catch_panic
PKStatus::Success.into()
}
This has two major consequences:
-
Undefined behaviour on panic:
- If
register_ntt()panics, the panic may unwind through the extern "C" boundary, causing undefined behaviour in C, which can result in app (iOS/Android) crashes or silent memory corruptions with no recoverable error code.
- If
-
Stale error state after successful init:
- Since
clear_last_error()is never called, any error set by a previous failing FFI call persists afterpk_init()returns success. So,pk_get_last_error()after successfulpk_init()may show a stale error message from an unrelated failure.
- Since
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Search the provekit-ffi sources for pk_init and the existing catch_panic wrapper used by other FFI functions. Confirm that initialization clears the prior error state and prevents register_ntt() panics from crossing the extern "C" boundary, then run the relevant FFI tests if available.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- api
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100