rpc: Sanitize label name in various RPCs

- importprivkey
- importaddress
- importpubkey
- listtransactions
- listsinceblock
- importmulti
- importdescriptors
This commit is contained in:
Aurèle Oulès committed 2023-01-04 12:31:28 +01:00
1 parent a653f4bb1f
commit 67e7ba8e1a
2 files changed
+7 -7

No files matched your search

+5 -5
View File
@@ -142,7 +142,7 @@ RPCHelpMan importprivkey()
std::string strSecret = request.params[0].get_str(); std::string strSecret = request.params[0].get_str();
std::string strLabel; std::string strLabel;
if (!request.params[1].isNull()) if (!request.params[1].isNull())
strLabel = request.params[1].get_str(); strLabel = LabelFromValue(request.params[1]);
// Whether to perform rescan after import // Whether to perform rescan after import
if (!request.params[2].isNull()) if (!request.params[2].isNull())
@@ -235,7 +235,7 @@ RPCHelpMan importaddress()
std::string strLabel; std::string strLabel;
if (!request.params[1].isNull()) if (!request.params[1].isNull())
strLabel = request.params[1].get_str(); strLabel = LabelFromValue(request.params[1]);
// Whether to perform rescan after import // Whether to perform rescan after import
bool fRescan = true; bool fRescan = true;
@@ -428,7 +428,7 @@ RPCHelpMan importpubkey()
std::string strLabel; std::string strLabel;
if (!request.params[1].isNull()) if (!request.params[1].isNull())
strLabel = request.params[1].get_str(); strLabel = LabelFromValue(request.params[1]);
// Whether to perform rescan after import // Whether to perform rescan after import
bool fRescan = true; bool fRescan = true;
@@ -1163,7 +1163,7 @@ static UniValue ProcessImport(CWallet& wallet, const UniValue& data, const int64
if (internal && data.exists("label")) { if (internal && data.exists("label")) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Internal addresses should not have a 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; const bool add_keypool = data.exists("keypool") ? data["keypool"].get_bool() : false;
// Add to keypool only works with privkeys disabled // 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 std::string& descriptor = data["desc"].get_str();
const bool active = data.exists("active") ? data["active"].get_bool() : false; const bool active = data.exists("active") ? data["active"].get_bool() : false;
const bool internal = data.exists("internal") ? data["internal"].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 // Parse descriptor string
FlatSigningProvider keys; FlatSigningProvider keys;
+2 -2
View File
@@ -487,7 +487,7 @@ RPCHelpMan listtransactions()
std::optional<std::string> filter_label; std::optional<std::string> filter_label;
if (!request.params[0].isNull() && request.params[0].get_str() != "*") { 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()) { if (filter_label.value().empty()) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Label argument must be a valid label name or \"*\"."); 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; std::optional<std::string> filter_label;
if (!request.params[5].isNull()) { 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; int depth = height ? wallet.GetLastBlockHeight() + 1 - *height : -1;