From 67e7ba8e1aea58fc864f9bb1fc0e56b70777185e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A8le=20Oul=C3=A8s?= Date: Thu, 15 Dec 2022 10:58:14 +0100 Subject: [PATCH] rpc: Sanitize label name in various RPCs - importprivkey - importaddress - importpubkey - listtransactions - listsinceblock - importmulti - importdescriptors --- src/wallet/rpc/backup.cpp | 10 +++++----- src/wallet/rpc/transactions.cpp | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/wallet/rpc/backup.cpp b/src/wallet/rpc/backup.cpp index ddf10cae155..6a0f8548f18 100644 --- a/src/wallet/rpc/backup.cpp +++ b/src/wallet/rpc/backup.cpp @@ -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; diff --git a/src/wallet/rpc/transactions.cpp b/src/wallet/rpc/transactions.cpp index 02a1ac5ea1e..844657a71cb 100644 --- a/src/wallet/rpc/transactions.cpp +++ b/src/wallet/rpc/transactions.cpp @@ -487,7 +487,7 @@ RPCHelpMan listtransactions() std::optional 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 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;