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

coins: replace `std::distance` with unambiguous pointer subtraction

Public commit record

What the developer wrote

Authored by Lőrinc

73/100 · Adequate
coins: replace `std::distance` with unambiguous pointer subtraction

Avoid calling `std::distance` on null pointers in `PoolResource::AllocateChunk`.
Compute remaining bytes with `m_available_memory_end - m_available_memory_it` instead, which is well-defined to be `0` when both are `nullptr`.

Co-authored-by: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context
The short version

What changed, and why it matters

This change fixes a low-level programming issue in Bitcoin Core's custom memory pool allocator. The old code used a standard library function (`std::distance`) to calculate how many unused bytes remained in a memory chunk. That function can have undefined behavior when given null pointers, which could occur when no chunk had been allocated yet. The new code uses plain pointer subtraction, which is explicitly defined to give zero when both pointers are null. The practical security impact is likely limited because the undefined behavior only arises in a specific no-memory-allocated state and the result is used only to decide whether to add leftover bytes to a freelist.

Recommended action

Treat as a code-quality and undefined-behavior hardening fix. Include in routine backports if the allocator is used in release branches. No emergency response is warranted absent evidence of exploitable memory corruption.

Security signals we found

01

Undefined behavior fix: `std::distance` on potentially null raw pointers

02

Memory allocator hardening in custom pool allocator

03

Pointer arithmetic made explicit and well-defined for equal-null case

04

No explicit security claim or CVE in commit message

Risk score

Why this scored 42/100

Our methodology →
Potential impact 12/30
Exploitability 8/25
Stealth signal 6/15
Affected reach 7/15
Confidence 6/10
Evidence quality 3/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.