0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-03-05 14:06:27 -05:00

rpc: Sanitize label name in various RPCs

- importprivkey
- importaddress
- importpubkey
- listtransactions
- listsinceblock
- importmulti
- importdescriptors
This commit is contained in:
Aurèle Oulès 2022-12-15 10:58:14 +01:00
parent a653f4bb1f
commit 67e7ba8e1a
No known key found for this signature in database
GPG key ID: 55F3976F7001D998
2 changed files with 7 additions and 7 deletions

View file

@ -142,7 +142,7 @@ RPCHelpMan importprivkey()
std::string strSecret = request.params[0].get_str();
std::string strLabel;
if (!request.params[1].isNull())
strLabel = request.params[1].get_str();
strLabel = LabelFromValue(request.params[1]);
// Whether to perform rescan after import
if (!request.params[2].isNull())
@ -235,7 +235,7 @@ RPCHelpMan importaddress()
std::string strLabel;
if (!request.params[1].isNull())
strLabel = request.params[1].get_str();
strLabel = LabelFromValue(request.params[1]);
// Whether to perform rescan after import
bool fRescan = true;
@ -428,7 +428,7 @@ RPCHelpMan importpubkey()
std::string strLabel;
if (!request.params[1].isNull())
strLabel = request.params[1].get_str();
strLabel = LabelFromValue(request.params[1]);
// Whether to perform rescan after import
bool fRescan = true;
@ -1163,7 +1163,7 @@ static UniValue ProcessImport(CWallet& wallet, const UniValue& data, const int64
if (internal && data.exists("label")) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Internal addresses should not have a label");
}
const std::string& label = data.exists("label") ? data["label"].get_str() : "";
const std::string& label = data.exists("label") ? LabelFromValue(data["label"]) : "";
const bool add_keypool = data.exists("keypool") ? data["keypool"].get_bool() : false;
// Add to keypool only works with privkeys disabled
@ -1457,7 +1457,7 @@ static UniValue ProcessDescriptorImport(CWallet& wallet, const UniValue& data, c
const std::string& descriptor = data["desc"].get_str();
const bool active = data.exists("active") ? data["active"].get_bool() : false;
const bool internal = data.exists("internal") ? data["internal"].get_bool() : false;
const std::string& label = data.exists("label") ? data["label"].get_str() : "";
const std::string& label = data.exists("label") ? LabelFromValue(data["label"]) : "";
// Parse descriptor string
FlatSigningProvider keys;

View file

@ -487,7 +487,7 @@ RPCHelpMan listtransactions()
std::optional<std::string> filter_label;
if (!request.params[0].isNull() && request.params[0].get_str() != "*") {
filter_label = request.params[0].get_str();
filter_label.emplace(LabelFromValue(request.params[0]));
if (filter_label.value().empty()) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Label argument must be a valid label name or \"*\".");
}
@ -637,7 +637,7 @@ RPCHelpMan listsinceblock()
std::optional<std::string> filter_label;
if (!request.params[5].isNull()) {
filter_label = request.params[5].get_str();
filter_label = LabelFromValue(request.params[5]);
}
int depth = height ? wallet.GetLastBlockHeight() + 1 - *height : -1;