Skip to content

lightningd: fail sendpay cleanly when the route does not fit the onion#9353

Open
ksedgwic wants to merge 1 commit into
ElementsProject:masterfrom
ksedgwic:sendpay-onion-overflow
Open

lightningd: fail sendpay cleanly when the route does not fit the onion#9353
ksedgwic wants to merge 1 commit into
ElementsProject:masterfrom
ksedgwic:sendpay-onion-overflow

Conversation

@ksedgwic

Copy link
Copy Markdown
Collaborator

Fixes #9352

sendpay with a route whose per-hop payloads exceed the 1300-byte onion crashes lightningd: create_onionpacket() returns NULL and send_payment() passed it to send_onion() unchecked, so serialize_onionpacket() dereferences NULL and the daemon dies with SIGSEGV. Observed in production on a 25-hop route submitted by a rebalancing plugin; backtrace in #9352.

The fix mirrors the NULL check the sendonion path already has, returning "Could not create onion packet" instead of crashing.

Adds test_sendpay_onion_overflow: a 30-hop route (25 hops can still fit at minimal encodings -- the limit is payload bytes, not hop count), which reproduced the production backtrace before the fix and now gets a clean RPC error with the node still up.

create_onionpacket returns NULL when the route's per-hop payloads
exceed the 1300-byte onion; send_payment passed the packet to
send_onion unchecked, and serialize_onionpacket dereferenced it,
killing lightningd with SIGSEGV.  Observed in production on a
25-hop route submitted by a rebalancing plugin.

The sendonion path already checks this call and fails the command;
mirror it, and add a test.

Changelog-Fixed: JSON-RPC: `sendpay` with a route too long to fit the onion packet now fails cleanly instead of crashing lightningd.
@ksedgwic
ksedgwic requested a review from Lagrang3 July 24, 2026 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

lightningd: SIGSEGV in serialize_onionpacket when a sendpay route's onion payloads exceed 1300 bytes

1 participant