pk_init missing catch_panic wrapper: panic UB + stale error state

Open Beginner friendly
#400 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
68/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
rust
Domain
api

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.

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:
  1. 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.
  2. Stale error state after successful init:

    • Since clear_last_error() is never called, any error set by a previous failing FFI call persists after pk_init() returns success. So, pk_get_last_error() after successful pk_init() may show a stale error message from an unrelated failure.
Dominant language
Noir
Stars
138
Forks
47
Avg merge
1d 34m
Merged PRs (30d)
6

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from worldfnd/provekit

All issues in worldfnd/provekit

Similar issues

More Backend & API Design issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.