From 1b8adabd4f1487fa1de431ca91a492cb542df1f8 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 17 Jul 2019 07:19:14 +0930 Subject: [PATCH] devtools/onion: fix --decode Add odd-length string can never be valid hex! In addition, don't try to print the next hop if there isn't one, but always print the (raw) payload. Signed-off-by: Rusty Russell --- devtools/onion.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/devtools/onion.c b/devtools/onion.c index 7c8cf08b8..1b0d66314 100644 --- a/devtools/onion.c +++ b/devtools/onion.c @@ -62,7 +62,7 @@ static void do_decode(int argc, char **argv) struct privkey seckey; const tal_t *ctx = talz(NULL, tal_t); u8 serialized[TOTAL_PACKET_SIZE]; - char hextemp[2 * sizeof(serialized) + 1]; + char hextemp[2 * sizeof(serialized)]; memset(hextemp, 0, sizeof(hextemp)); u8 shared_secret[32]; u8 assocdata[32]; @@ -97,11 +97,13 @@ static void do_decode(int argc, char **argv) if (!step || !step->next) errx(1, "Error processing message."); - u8 *ser = serialize_onionpacket(ctx, step->next); - if (!ser) - errx(1, "Error serializing message."); - - printf("%s\n", tal_hex(ctx, ser)); + printf("payload=%s\n", tal_hex(ctx, step->raw_payload)); + if (step->nextcase == ONION_FORWARD) { + u8 *ser = serialize_onionpacket(ctx, step->next); + if (!ser) + errx(1, "Error serializing message."); + printf("next=%s\n", tal_hex(ctx, ser)); + } tal_free(ctx); }