Skip to content

Commit 8a6bc6a

Browse files
morehouserustyrussell
authored andcommitted
bolt11: don't abort on invalid pubkey
Rather than crashing the entire node on invalid pubkey, we should return an error. Detected by libFuzzer: ==250024== ERROR: libFuzzer: deadly signal [ Changed so that `n` really does check that it's valid --RR ] #7 abort #8 bolt11_decode common/bolt11.c:1002:4
1 parent 440fe8c commit 8a6bc6a

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

common/bolt11.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,14 +306,24 @@ static const char *decode_n(struct bolt11 *b11,
306306
const u5 **data, size_t *field_len,
307307
bool *have_n)
308308
{
309+
const char *err;
310+
struct pubkey k;
311+
309312
assert(!*have_n);
310313
/* BOLT #11:
311314
*
312315
* A reader... MUST skip over unknown fields, OR an `f` field
313316
* with unknown `version`, OR `p`, `h`, `s` or `n` fields that do
314317
* NOT have `data_length`s of 52, 52, 52 or 53, respectively. */
315-
return pull_expected_length(b11, hu5, data, field_len, 53, 'n',
316-
have_n, &b11->receiver_id.k);
318+
err = pull_expected_length(b11, hu5, data, field_len, 53, 'n',
319+
have_n, &b11->receiver_id.k);
320+
if (err)
321+
return err;
322+
323+
if (!pubkey_from_node_id(&k, &b11->receiver_id))
324+
return tal_fmt(b11, "invalid public key %s",
325+
node_id_to_hexstr(tmpctx, &b11->receiver_id));
326+
return NULL;
317327
}
318328

319329
/* BOLT #11:

0 commit comments

Comments
 (0)