AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Moderate 62 Bitcoin

kernel: guard btck::Handle move-assignment against self-move

Public commit record

What the developer wrote

Authored by Thomas

73/100 · Adequate
kernel: guard btck::Handle move-assignment against self-move

The move-assignment operator for btck::Handle<> unconditionally called
DestroyFunc(m_ptr) before reading the source pointer. On a self-move
(h = std::move(h)), this destroyed the held resource and then reassigned
the now-dangling pointer back to m_ptr via std::exchange, leading to a
double-free when the object is later destroyed.

Mirror the existing self-check in the copy-assignment operator by
guarding the move-assignment with 'if (this != &other)' so a self-move
becomes a no-op, leaving the object in a valid state as required by the
standard library.

Handle<> is the base of 16 public types in the kernel C++ API wrapper
(Transaction, Block, BlockHeader, ChainParams, Context, Coin,
BlockValidationState, ScriptPubkey, TransactionOutput, Txid, OutPoint,
TransactionInput, PrecomputedTransactionData, BlockHash,
BlockSpentOutputs, TransactionSpentOutputs), so self-move can arise
from generic algorithms operating on containers of these types.

Extend CheckHandle in test_kernel to cover self-move-assignment for
every Handle-derived type.
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context
The short version

What changed, and why it matters

This commit fixes a bug in Bitcoin Core's kernel C++ API wrapper where a special kind of assignment—moving an object into itself—could accidentally destroy its own underlying resource and later cause a crash (double-free) when the object is cleaned up. The fix adds a self-check, similar to one already used for copy assignment, so self-moves do nothing harmful. The change also adds tests for all 16 public types built on this wrapper.

Recommended action

Apply the patch. The fix is small, well-scoped, and includes regression tests. Review any code using these kernel API types with containers or algorithms that may perform moves (e.g., sorting, vector reallocation) to ensure the fix is present.

Security signals we found

01

Double-free/use-after-free in resource-managing wrapper

02

Self-move-assignment not guarded

03

Affects 16 public kernel API types

04

Could be triggered by generic container/algorithms

05

Existing copy-assignment had self-check but move-assignment did not

Risk score

Why this scored 62/100

Our methodology →
Potential impact 18/30
Exploitability 8/25
Stealth signal 10/15
Affected reach 12/15
Confidence 9/10
Evidence quality 5/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.