Skip to content

Commit 8a9349a

Browse files
committed
bolt11: don't abort on invalid pubkey
Rather than crashing the entire node on invalid pubkey, check the validity of the pubkey in decode_n, and return an error if invalid. Detected by libFuzzer: ==265599== ERROR: libFuzzer: deadly signal ElementsProject#7 abort ElementsProject#8 bolt11_decode common/bolt11.c:999:4
1 parent a3eeed7 commit 8a9349a

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

common/bolt11.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,14 +306,27 @@ 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+
309311
assert(!*have_n);
310312
/* BOLT #11:
311313
*
312314
* A reader... MUST skip over unknown fields, OR an `f` field
313315
* with unknown `version`, OR `p`, `h`, `s` or `n` fields that do
314316
* 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);
317+
err = pull_expected_length(b11, hu5, data, field_len, 53, 'n', have_n,
318+
&b11->receiver_id.k);
319+
320+
/* If that gave us a node ID, check it. */
321+
if (*have_n) {
322+
struct pubkey k;
323+
if (!pubkey_from_node_id(&k, &b11->receiver_id))
324+
return tal_fmt(
325+
b11, "invalid public key %s",
326+
node_id_to_hexstr(tmpctx, &b11->receiver_id));
327+
}
328+
329+
return err;
317330
}
318331

319332
/* BOLT #11:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lnbc1qqqqpqqnp4qqqlftcw9qqqqqqqqqqqqygh9qpp5qpp5s7zxqqqqcqpjpqqygh9qpp5s7zxqqqqcqpjpqqlqqqqqqqqqqqqcqqpqqqqqqqqqqqsqqqqqqqqdqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqlqqqcqpjptfqptfqptfqpqqqqqqqqqqqqqqqqqqq8ddm0a

0 commit comments

Comments
 (0)