diff --git a/devtools/onion.c b/devtools/onion.c index 5ebca0578..5a8d53eaf 100644 --- a/devtools/onion.c +++ b/devtools/onion.c @@ -220,15 +220,16 @@ static void runtest(const char *filename) json_to_pubkey(buffer, pubkeytok, &pubkey); if (!typetok || json_tok_streq(buffer, typetok, "legacy")) { /* Legacy has a single 0 prepended as "realm" byte */ - full = tal_arrz(ctx, u8, 1); + full = tal_arrz(ctx, u8, 33); + memcpy(full + 1, payload, tal_bytelen(payload)); } else { /* TLV has length prepended */ full = tal_arr(ctx, u8, 0); towire_bigsize(&full, tal_bytelen(payload)); + prepended = tal_bytelen(full); + tal_resize(&full, prepended + tal_bytelen(payload)); + memcpy(full + prepended, payload, tal_bytelen(payload)); } - prepended = tal_bytelen(full); - tal_resize(&full, prepended + tal_bytelen(payload)); - memcpy(full + prepended, payload, tal_bytelen(payload)); sphinx_add_hop(path, &pubkey, full); } res = create_onionpacket(ctx, path, &shared_secrets);