aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Chow <github@achow101.com>2023-06-01 17:42:24 -0400
committerAndrew Chow <github@achow101.com>2023-06-01 17:43:07 -0400
commita537cb0b8780c53c8af425709d4c939b9ec79057 (patch)
tree8fc9a4f3122090aec10ec152a3e46bb6336ecd1e /src
parent3116ccd790e76de8f64d2ef9aa5a2641c15bbd8b (diff)
parentc2e9214effe9abecae6f81cb10158f9661065da3 (diff)
Merge bitcoin/bitcoin#27755: [24.x] rpc: Fix invalid bech32 handling
c2e9214effe9abecae6f81cb10158f9661065da3 rpc: Fix invalid bech32 handling (MarcoFalke) Pull request description: Backports https://github.com/bitcoin/bitcoin/pull/27727 to 24.x. Not a clean cherry-pick. ACKs for top commit: achow101: ACK c2e9214effe9abecae6f81cb10158f9661065da3 stickies-v: ACK c2e9214effe9abecae6f81cb10158f9661065da3 Tree-SHA512: 8fd5b4c0016e9f30061e327b5f75320e4ed27b1a7b61eafabefe87d351ab13c970e969ea85b2f4cab44c1b0f28214ee7c5b85e3e0549345b57f1fa724e3c814c
Diffstat (limited to 'src')
-rw-r--r--src/key_io.cpp17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/key_io.cpp b/src/key_io.cpp
index 6dd6f82112..d77829e046 100644
--- a/src/key_io.cpp
+++ b/src/key_io.cpp
@@ -109,13 +109,13 @@ CTxDestination DecodeDestination(const std::string& str, const CChainParams& par
std::equal(pubkey_prefix.begin(), pubkey_prefix.end(), data.begin()))) {
error_str = "Invalid length for Base58 address";
} else {
- error_str = "Invalid prefix for Base58-encoded address";
+ error_str = "Invalid or unsupported Base58-encoded address.";
}
return CNoDestination();
} else if (!is_bech32) {
// Try Base58 decoding without the checksum, using a much larger max length
if (!DecodeBase58(str, data, 100)) {
- error_str = "Not a valid Bech32 or Base58 encoding";
+ error_str = "Invalid or unsupported Segwit (Bech32) or Base58 encoding.";
} else {
error_str = "Invalid checksum or length of Base58 address";
}
@@ -124,7 +124,11 @@ CTxDestination DecodeDestination(const std::string& str, const CChainParams& par
data.clear();
const auto dec = bech32::Decode(str);
- if ((dec.encoding == bech32::Encoding::BECH32 || dec.encoding == bech32::Encoding::BECH32M) && dec.data.size() > 0) {
+ if (dec.encoding == bech32::Encoding::BECH32 || dec.encoding == bech32::Encoding::BECH32M) {
+ if (dec.data.empty()) {
+ error_str = "Empty Bech32 data section";
+ return CNoDestination();
+ }
// Bech32 decoding
if (dec.hrp != params.Bech32HRP()) {
error_str = "Invalid prefix for Bech32 address";
@@ -158,7 +162,7 @@ CTxDestination DecodeDestination(const std::string& str, const CChainParams& par
}
}
- error_str = "Invalid Bech32 v0 address data size";
+ error_str = strprintf("Invalid Bech32 v0 address program size (%s byte), per BIP141", data.size());
return CNoDestination();
}
@@ -175,7 +179,7 @@ CTxDestination DecodeDestination(const std::string& str, const CChainParams& par
}
if (data.size() < 2 || data.size() > BECH32_WITNESS_PROG_MAX_LEN) {
- error_str = "Invalid Bech32 address data size";
+ error_str = strprintf("Invalid Bech32 address program size (%s byte)", data.size());
return CNoDestination();
}
@@ -184,6 +188,9 @@ CTxDestination DecodeDestination(const std::string& str, const CChainParams& par
std::copy(data.begin(), data.end(), unk.program);
unk.length = data.size();
return unk;
+ } else {
+ error_str = strprintf("Invalid padding in Bech32 data section");
+ return CNoDestination();
}
}