Skip to content

Commit

Permalink
Check hex_decode(...) return value
Browse files Browse the repository at this point in the history
  • Loading branch information
practicalswift authored and rustyrussell committed Mar 19, 2018
1 parent 9efe123 commit 148aaa7
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions devtools/onion.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ static void do_generate(int argc, char **argv)
memset(&assocdata, 'B', sizeof(assocdata));

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

hex_decode(hextemp, sizeof(hextemp), serialized, sizeof(serialized));
if (!hex_decode(hextemp, sizeof(hextemp), serialized, sizeof(serialized))) {
errx(1, "Invalid onion hex '%s'", hextemp);
}

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

Expand Down

0 comments on commit 148aaa7

Please sign in to comment.