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

peer: fix nil deref in newPingPayload on BestBlockHeader error

Public commit record

What the developer wrote

Authored by Elle Mouton

85/100 · Strong
peer: fix nil deref in newPingPayload on BestBlockHeader error

The condition guarding the early return used && when it should have
used ||. When BestBlockHeader returns an error with a nil header, the
old code only short-circuited if the nil header equalled
lastBlockHeader. Otherwise it fell through to header.Serialize(),
causing a nil pointer dereference panic.

Change the condition to return the cached serialized header whenever
there is an error OR when the header is unchanged.
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Explains rationale or failure mode
The short version

What changed, and why it matters

This commit fixes a simple but real programming bug: a logical 'and' was used where an 'or' was needed. In the LND lightning node software, when preparing a network ping message, the code asks for the latest Bitcoin block header. If that lookup fails and returns no header, the old code would try to use the missing header and crash the program with a nil pointer panic. The fix makes the code return a cached header whenever the lookup errors OR when the header hasn't changed, preventing the crash.

Recommended action

Apply the patch. It is a one-line correctness fix with low risk. Nodes should upgrade to avoid potential crashes during peer ping exchange when BestBlockHeader returns an error.

Security signals we found

01

nil pointer dereference panic in peer message handling

02

logic operator bug (&& vs ||) causing incorrect error handling

03

denial-of-service vector: unhandled error path in ping payload construction

Risk score

Why this scored 42/100

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