Skip to content

Commit

Permalink
wire: Use the last 1 to separate the hrp from bech32 strings
Browse files Browse the repository at this point in the history
We were failing to decode some invoices because we were splitting on
the first `1`, not the last one. This would then result in the parsing
to break because 1 is not mapped in the u5 mapping.

Changelog-Fixed: pay: Parsing some bolt11 strings would fail if an amount is specified and the network mismatched.
  • Loading branch information
cdecker committed Mar 2, 2021
1 parent 772daec commit 3822c35
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion common/bech32_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ bool from_bech32_charset(const tal_t *ctx,
bool upper = false, lower = false;
size_t datalen;

sep = memchr(bech32, '1', bech32_len);
sep = memrchr(bech32, '1', bech32_len);
if (!sep)
return false;

Expand Down
3 changes: 2 additions & 1 deletion common/bolt12.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ static const u8 *string_to_data(const tal_t *ctx,
*fail = tal_fmt(ctx, "invalid bech32 string");
return NULL;
}
if (!streq(hrp, hrp_expected)) {

if (strlen(hrp) <= strlen(hrp_expected) || !strstarts(hrp, hrp_expected)) {
*fail = tal_fmt(ctx, "unexpected prefix %s", hrp);
data = tal_free(data);
} else
Expand Down

0 comments on commit 3822c35

Please sign in to comment.