Skip to content

Commit 148aaa7

Browse files
practicalswiftrustyrussell
authored andcommitted
Check hex_decode(...) return value
1 parent 9efe123 commit 148aaa7

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

devtools/onion.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ static void do_generate(int argc, char **argv)
2424
memset(&assocdata, 'B', sizeof(assocdata));
2525

2626
for (int i = 0; i < num_hops; i++) {
27-
hex_decode(argv[1 + i], 66, privkeys[i], 33);
27+
if (!hex_decode(argv[1 + i], 66, privkeys[i], 33)) {
28+
errx(1, "Invalid private key hex '%s'", argv[1 + i]);
29+
}
2830
if (secp256k1_ec_pubkey_create(secp256k1_ctx, &path[i].pubkey,
2931
privkeys[i]) != 1)
3032
errx(1, "Could not decode pubkey");
@@ -76,7 +78,9 @@ static void do_decode(int argc, char **argv)
7678
if (!read_all(STDIN_FILENO, hextemp, sizeof(hextemp)))
7779
errx(1, "Reading in onion");
7880

79-
hex_decode(hextemp, sizeof(hextemp), serialized, sizeof(serialized));
81+
if (!hex_decode(hextemp, sizeof(hextemp), serialized, sizeof(serialized))) {
82+
errx(1, "Invalid onion hex '%s'", hextemp);
83+
}
8084

8185
msg = parse_onionpacket(ctx, serialized, sizeof(serialized));
8286

0 commit comments

Comments
 (0)