diff --git a/common/sphinx.c b/common/sphinx.c index 5163c3188..ffccf3c2d 100644 --- a/common/sphinx.c +++ b/common/sphinx.c @@ -98,7 +98,6 @@ void sphinx_add_hop(struct sphinx_path *path, const struct pubkey *pubkey, sp.raw_payload = tal_dup_arr(path, u8, payload, tal_count(payload), 0); sp.pubkey = *pubkey; tal_arr_expand(&path->hops, sp); - assert(sphinx_path_payloads_size(path) <= ROUTING_INFO_SIZE); } /* Small helper to append data to a buffer and update the position @@ -396,6 +395,12 @@ struct onionpacket *create_onionpacket( struct hop_params *params; struct secret *secrets = tal_arr(ctx, struct secret, num_hops); + if (sphinx_path_payloads_size(sp) > ROUTING_INFO_SIZE) { + tal_free(packet); + tal_free(secrets); + return NULL; + } + if (sp->session_key == NULL) { sp->session_key = tal(sp, struct secret); randombytes_buf(sp->session_key, sizeof(struct secret)); diff --git a/lightningd/pay.c b/lightningd/pay.c index df37742a4..cd21140ab 100644 --- a/lightningd/pay.c +++ b/lightningd/pay.c @@ -1460,6 +1460,11 @@ static struct command_result *json_createonion(struct command *cmd, for (size_t i=0; i ROUTING_INFO_SIZE) + return command_fail( + cmd, JSONRPC2_INVALID_PARAMS, + "Payloads exceed maximum onion packet size."); + packet = create_onionpacket(cmd, sp, &shared_secrets); if (!packet) return command_fail(cmd, LIGHTNINGD, diff --git a/tests/test_pay.py b/tests/test_pay.py index 568b23c9f..949343109 100644 --- a/tests/test_pay.py +++ b/tests/test_pay.py @@ -2718,7 +2718,6 @@ def test_partial_payment_htlc_loss(node_factory, bitcoind): l1.rpc.waitsendpay(payment_hash=inv['payment_hash'], timeout=TIMEOUT, partid=1) -@pytest.mark.xfail(strict=True) def test_createonion_limits(node_factory): l1, = node_factory.get_nodes(1) hops = [{