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

lightningd: don't crash when truncating large log messages

Public commit record

What the developer wrote

Authored by Matt Whitlock

81/100 · Strong
lightningd: don't crash when truncating large log messages

It's not okay to call free() on the pointer to a truncated log message
that was allocated by tal_fmt() in cap_header(). Let's call tal_free()
instead, and rather than calling vasprintf() to malloc the log message in
the first place, let's call tal_vfmt().

Also, since we're now always using a tallocated string for the log message,
let's have cap_header() take ownership of it and either free it if it
truncated the message (and is returning a different pointer to the truncated
message) or else return the taken original pointer without freeing it.

Also, log_io()'s str and data parameters are marked TAKES, but the function
was not actually taking them, so fix that up too.

Also, don't call strlen() on a string returned by tal_fmt(). The returned
pointer is guaranteed to have tal_count() == strlen() + 1, so there's no
sense in scanning through the string to find its length.

Suggested-by: Lagrang3 <lagrang3@protonmail.com>
See: https://github.com/ElementsProject/lightning/pull/9331#discussion_r3628600315

Changelog-Fixed: log: don't crash when truncating large log messages
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Links an issue, advisory, or supporting reference
The short version

What changed, and why it matters

This commit fixes a crash bug in Core Lightning's logging code. When a log message was very long and got truncated, the program accidentally used the standard free() on memory that had been allocated by the project's own tal allocation system, causing a crash. The patch switches everything to use tal consistently, marks some function parameters as 'taken' so ownership is clear, and removes a failing-test marker because the bug is now fixed.

Recommended action

Upgrade to a release containing this commit. The bug is a remotely or plugin-triggerable denial-of-service crash; no immediate workaround is required beyond patching. Operators running nodes that load untrusted or verbose plugins should prioritize the update.

Security signals we found

01

Use-after-free / allocator mismatch: free() called on tal-allocated memory

02

Denial of service via large log message triggering truncation path crash

03

Memory ownership semantics corrected with TAKES annotations

04

Test previously expected to fail is now enabled, confirming the crash path

Risk score

Why this scored 60/100

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