Skip to content

pk_init missing catch_panic wrapper: panic UB + stale error state #400

@x-senpai-x

Description

@x-senpai-x

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions