Skip to content

common/bolt11: Fix BOLT11 hash calculation for unknown fallback address versions #8302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions common/bolt11.c
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,18 @@ static const char *decode_f(struct bolt11 *b11,
size_t orig_len = *field_len;
const char *err;

/* Read version but don't commit to hash yet */
err = pull_uint(NULL, &orig_data, &orig_len, &version, 5);
if (err)
return tal_fmt(b11, "f: %s", err);

bool is_known_version = version == 17 || version == 18 || version < 17;

if (!is_known_version) {
return unknown_field(b11, hu5, data, field_len, 'f');
}

/* For known versions, process with hash */
err = pull_uint(hu5, data, field_len, &version, 5);
if (err)
return tal_fmt(b11, "f: %s", err);
Expand Down Expand Up @@ -429,10 +441,9 @@ static const char *decode_f(struct bolt11 *b11,
fallback = scriptpubkey_witness_raw(b11, version,
f, tal_count(f));
} else {
/* Restore version for unknown field! */
*data = orig_data;
*field_len = orig_len;
return unknown_field(b11, hu5, data, field_len, 'f');
// This should be unreachable because all valid versions (17, 18, or <17)
// and invalid versions are caught above.
return tal_fmt(b11, "f: unknown version %"PRIu64, version);
}

if (b11->fallbacks == NULL)
Expand Down Expand Up @@ -1372,4 +1383,4 @@ char *bolt11_encode_(const tal_t *ctx,
output = tal_free(output);

return output;
}
}
Loading