diff --git a/segwit_addr.c b/segwit_addr.c index e5b26ec91a..8202d84181 100644 --- a/segwit_addr.c +++ b/segwit_addr.c @@ -51,9 +51,13 @@ int bech32_encode(char *output, const char *hrp, const uint8_t *data, size_t dat uint32_t chk = 1; size_t i = 0; while (hrp[i] != 0) { - if (hrp[i] >= 'A' && hrp[i] <= 'Z') return 0; - if (!(hrp[i] >> 5)) return 0; - chk = bech32_polymod_step(chk) ^ (hrp[i] >> 5); + int ch = hrp[i]; + if (ch < 33 || ch > 126) { + return 0; + } + + if (ch >= 'A' && ch <= 'Z') return 0; + chk = bech32_polymod_step(chk) ^ (ch >> 5); ++i; } if (i + 7 + data_len > 90) return 0;