Skip to content

Commit

Permalink
bolt11: return error on unexpected lightning prefix
Browse files Browse the repository at this point in the history
Remove the assertion so that an error is returned for invalid bech32.
An error is preferable to crashing the entire node if there's an extra
"lightning:" prefix:

  $ lightning-cli pay "lightning:lightning:"

Node log:
  pay: common/bolt11.c:718: bolt11_decode_nosig: Assertion `!has_lightning_prefix(str)' failed.
  pay: FATAL SIGNAL 6
  ...
  INFO    plugin-pay: Killing plugin: exited during normal operation
  **BROKEN** plugin-pay: Plugin marked as important, shutting down lightningd
  • Loading branch information
morehouse authored and rustyrussell committed Oct 17, 2023
1 parent 74b8fff commit ee8cf69
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 7 deletions.
1 change: 0 additions & 1 deletion common/bolt11.c
Expand Up @@ -721,7 +721,6 @@ struct bolt11 *bolt11_decode_nosig(const tal_t *ctx, const char *str,
memset(have_field, 0, sizeof(have_field));
b11->routes = tal_arr(b11, struct route_info *, 0);

assert(!has_lightning_prefix(str));
if (strlen(str) < 8)
return decode_fail(b11, fail, "Bad bech32 string");

Expand Down
@@ -0,0 +1 @@
lightning:
6 changes: 0 additions & 6 deletions tests/fuzz/fuzz-bolt11.c
Expand Up @@ -102,12 +102,6 @@ size_t LLVMFuzzerCustomMutator(uint8_t *fuzz_data, size_t size, size_t max_size,
return initial_input(fuzz_data, size, max_size);
}

// Strip (repeated) "lightning:" prefixes
while (strstarts(output, "lightning:") ||
strstarts(output, "LIGHTNING:")) {
output = (char *)to_canonical_invstr(tmpctx, output);
}

// Write the result into `fuzz_data`.
size_t output_len = strlen(output);
if (output_len > max_size)
Expand Down

0 comments on commit ee8cf69

Please sign in to comment.