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

common/json_parse_simple: drop redundant and wrong json_str_to_u64()

Public commit record

What the developer wrote

Authored by Matt Whitlock

73/100 · Adequate
common/json_parse_simple: drop redundant and wrong json_str_to_u64()

The json_str_to_u64() function contains incorrect logic. It chops one character
off of the beginning and end of the JSMN token and then parses the remainder as
a u64, but JSMN_STRING tokens already do not include the enclosing quotation
marks, so json_str_to_u64() would actually parse the JSON string "1234" into
the integer 23. Oops! Also note that it would simply fail on all input strings
shorter than two characters since tok->end would wind up *before* tok->start.

Just drop the function entirely. It was only used in one place, and that place
explicitly doesn't care whether its input is a JSON number or a numeric string,
and it was already calling json_to_u64() as an alternative, and that function
already accepts both JSON strings and JSON numbers as input, so the call to
json_str_to_u64() would have been entirely redundant if it had been correct.

Changelog-Fixed: The `keysend` command no longer corrupts the type numbers of extra TLVs when they are specified as numeric strings longer than 2 digits.
✓ 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 Core Lightning's JSON parsing. A helper function meant to read a number from a quoted JSON string was accidentally stripping one digit from each end. For example, the string "1234" was being read as 23, and single-digit strings failed entirely. The only user of this broken helper was the `keysend` command's handling of extra TLV (custom data) type numbers. As a result, when a user specified extra TLV type numbers as quoted numeric strings of more than two digits, the wrong type number would be stored and sent. This could cause payments to include malformed custom data, potentially making them fail or be misinterpreted by the recipient.

Recommended action

Apply the patch. It is a clean removal of a buggy, redundant function with no functional loss because `json_to_u64()` already handles both JSON strings and numbers. Users running `keysend` with quoted extra TLV type numbers should upgrade to avoid corrupted TLV types.

Security signals we found

01

Data corruption / incorrect TLV type encoding in keysend payments

02

Logic error in JSON token boundary handling

03

Redundant code path masked the bug until code review/refactoring

04

Potential payment failure or interoperability issue due to malformed extra TLVs

Risk score

Why this scored 62/100

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