diff --git a/nostrdb/src/bolt11/bech32.c b/nostrdb/src/bolt11/bech32.c index e1c9e183..5b335b98 100644 --- a/nostrdb/src/bolt11/bech32.c +++ b/nostrdb/src/bolt11/bech32.c @@ -104,7 +104,9 @@ bech32_encoding bech32_decode_len(char* hrp, uint8_t *data, size_t *data_len, co ++(*data_len); } hrp_len = input_len - (1 + *data_len); - if (hrp_len > max_hrp_len) + // Maximum amount of text content is buffer length - 1 byte, to account for the null-terminator + int max_hrp_content_len = max_hrp_len - 1; + if (hrp_len > max_hrp_content_len) return BECH32_ENCODING_NONE; if (1 + *data_len >= input_len || *data_len < 6) { return BECH32_ENCODING_NONE; diff --git a/nostrdb/src/nostr_bech32.c b/nostrdb/src/nostr_bech32.c index 10aba8ab..1affb1af 100644 --- a/nostrdb/src/nostr_bech32.c +++ b/nostrdb/src/nostr_bech32.c @@ -307,7 +307,7 @@ int parse_nostr_bech32(unsigned char *buf, int buflen, unsigned char *start; size_t parsed_len, u5_out_len, u8_out_len; enum nostr_bech32_type type; -#define MAX_PREFIX 8 + #define MAX_PREFIX 9 // 8 bytes for the text, 1 byte for the null terminator struct cursor cur, bech32, u8; make_cursor(buf, buf + buflen, &cur);