Skip to content

Commit 2b023be

Browse files
committed
bolt11: don't accept wrong-length p, h, s or n fields.
Spec got stricter. Signed-off-by: Rusty Russell <[email protected]>
1 parent 17b3fb5 commit 2b023be

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ CCANDIR := ccan
2626

2727
# Where we keep the BOLT RFCs
2828
BOLTDIR := ../bolts/
29-
DEFAULT_BOLTVERSION := 011bf84d74d130c2972becca97c87f297b9d4a92
29+
DEFAULT_BOLTVERSION := 68881992b97f20aca29edf7a4d673b8e6a70379a
3030
# Can be overridden on cmdline.
3131
BOLTVERSION := $(DEFAULT_BOLTVERSION)
3232

common/bolt11.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -179,16 +179,15 @@ static const char *decode_p(struct bolt11 *b11,
179179
{
180180
/* BOLT #11:
181181
*
182-
* A payer... SHOULD use the first `p` field that it did NOT
183-
* skip as the payment hash.
182+
* A payer... SHOULD use the first `p` field as the payment hash.
184183
*/
185184
assert(!*have_p);
186185

187186
/* BOLT #11:
188187
*
189-
* A reader... MUST skip over unknown fields, OR an `f` field
190-
* with unknown `version`, OR `p`, `h`, `s` or `n` fields that do
191-
* NOT have `data_length`s of 52, 52, 52 or 53, respectively.
188+
* A reader...
189+
* - MUST fail the payment if any mandatory field (`p`, `h`, `s`, `n`)
190+
* does not have the correct length (52, 52, 52, 53).
192191
*/
193192
return pull_expected_length(b11, hu5, data, field_len, 52, 'p',
194193
have_p, &b11->payment_hash);
@@ -240,9 +239,9 @@ static const char *decode_h(struct bolt11 *b11,
240239
assert(!*have_h);
241240
/* BOLT #11:
242241
*
243-
* A reader... MUST skip over unknown fields, OR an `f` field
244-
* with unknown `version`, OR `p`, `h`, `s` or `n` fields that do
245-
* NOT have `data_length`s of 52, 52, 52 or 53, respectively. */
242+
* A reader...
243+
* - MUST fail the payment if any mandatory field (`p`, `h`, `s`, `n`)
244+
* does not have the correct length (52, 52, 52, 53). */
246245
err = pull_expected_length(b11, hu5, data, field_len, 52, 'h',
247246
have_h, &hash);
248247

@@ -325,9 +324,9 @@ static const char *decode_n(struct bolt11 *b11,
325324
assert(!*have_n);
326325
/* BOLT #11:
327326
*
328-
* A reader... MUST skip over unknown fields, OR an `f` field
329-
* with unknown `version`, OR `p`, `h`, `s` or `n` fields that do
330-
* NOT have `data_length`s of 52, 52, 52 or 53, respectively. */
327+
* A reader...
328+
* - MUST fail the payment if any mandatory field (`p`, `h`, `s`, `n`)
329+
* does not have the correct length (52, 52, 52, 53). */
331330
err = pull_expected_length(b11, hu5, data, field_len, 53, 'n', have_n,
332331
&b11->receiver_id.k);
333332

@@ -361,9 +360,9 @@ static const char *decode_s(struct bolt11 *b11,
361360

362361
/* BOLT #11:
363362
*
364-
* A reader... MUST skip over unknown fields, OR an `f` field
365-
* with unknown `version`, OR `p`, `h`, `s` or `n` fields that do
366-
* NOT have `data_length`s of 52, 52, 52 or 53, respectively. */
363+
* A reader...
364+
* - MUST fail the payment if any mandatory field (`p`, `h`, `s`, `n`)
365+
* does not have the correct length (52, 52, 52, 53). */
367366
err = pull_expected_length(b11, hu5, data, field_len, 52, 's',
368367
have_s, &secret);
369368
if (*have_s)
@@ -443,6 +442,9 @@ static const char *decode_f(struct bolt11 *b11,
443442
fallback = scriptpubkey_witness_raw(b11, version,
444443
f, tal_count(f));
445444
} else {
445+
/* BOLT #11:
446+
* - MUST skip over `f` fields that use an unknown `version`.
447+
*/
446448
/* Restore version for unknown field! */
447449
*data = orig_data;
448450
*field_len = orig_len;
@@ -664,8 +666,7 @@ struct decoder {
664666
static const struct decoder decoders[] = {
665667
/* BOLT #11:
666668
*
667-
* A payer... SHOULD use the first `p` field that it did NOT
668-
* skip as the payment hash.
669+
* A payer... SHOULD use the first `p` field as the payment hash.
669670
*/
670671
{ 'p', false, decode_p },
671672
{ 'd', false, decode_d },

0 commit comments

Comments
 (0)