Skip to content

kernel: fail closed on invalid C API caller inputs #35339

@fallintoplace

Description

@fallintoplace

Several exported libbitcoinkernel C API functions currently rely on assertions for caller-provided runtime inputs, including transaction/block index accessors, script verification flags and input indexes, precomputed transaction data spent-output arrays, and block undo accessors.

The public header describes error reporting through return values and status out parameters. For external callers, invalid runtime input should fail closed with nullptr, 0, or a specific status rather than terminating the process through an assertion.

Examples of affected areas:

  • btck_transaction_get_output_at and btck_transaction_get_input_at
  • btck_script_pubkey_verify
  • btck_precomputed_transaction_data_create
  • btck_block_get_transaction_at
  • btck_block_spent_outputs_get_transaction_spent_outputs_at
  • btck_transaction_spent_outputs_get_coin_at

Expected behavior:

  • Out-of-range accessor indexes return nullptr.
  • Unsupported script verification flag bits return 0 and set a status.
  • Out-of-range script verification input indexes return 0 and set a status.
  • Malformed spent-output arrays return nullptr.

This would make the experimental C API more robust for external consumers while preserving the existing non-null handle preconditions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions