Skip to content

Commit 67e7ba8

Browse files
committed
rpc: Sanitize label name in various RPCs
- importprivkey - importaddress - importpubkey - listtransactions - listsinceblock - importmulti - importdescriptors
1 parent a653f4b commit 67e7ba8

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/wallet/rpc/backup.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ RPCHelpMan importprivkey()
142142
std::string strSecret = request.params[0].get_str();
143143
std::string strLabel;
144144
if (!request.params[1].isNull())
145-
strLabel = request.params[1].get_str();
145+
strLabel = LabelFromValue(request.params[1]);
146146

147147
// Whether to perform rescan after import
148148
if (!request.params[2].isNull())
@@ -235,7 +235,7 @@ RPCHelpMan importaddress()
235235

236236
std::string strLabel;
237237
if (!request.params[1].isNull())
238-
strLabel = request.params[1].get_str();
238+
strLabel = LabelFromValue(request.params[1]);
239239

240240
// Whether to perform rescan after import
241241
bool fRescan = true;
@@ -428,7 +428,7 @@ RPCHelpMan importpubkey()
428428

429429
std::string strLabel;
430430
if (!request.params[1].isNull())
431-
strLabel = request.params[1].get_str();
431+
strLabel = LabelFromValue(request.params[1]);
432432

433433
// Whether to perform rescan after import
434434
bool fRescan = true;
@@ -1163,7 +1163,7 @@ static UniValue ProcessImport(CWallet& wallet, const UniValue& data, const int64
11631163
if (internal && data.exists("label")) {
11641164
throw JSONRPCError(RPC_INVALID_PARAMETER, "Internal addresses should not have a label");
11651165
}
1166-
const std::string& label = data.exists("label") ? data["label"].get_str() : "";
1166+
const std::string& label = data.exists("label") ? LabelFromValue(data["label"]) : "";
11671167
const bool add_keypool = data.exists("keypool") ? data["keypool"].get_bool() : false;
11681168

11691169
// Add to keypool only works with privkeys disabled
@@ -1457,7 +1457,7 @@ static UniValue ProcessDescriptorImport(CWallet& wallet, const UniValue& data, c
14571457
const std::string& descriptor = data["desc"].get_str();
14581458
const bool active = data.exists("active") ? data["active"].get_bool() : false;
14591459
const bool internal = data.exists("internal") ? data["internal"].get_bool() : false;
1460-
const std::string& label = data.exists("label") ? data["label"].get_str() : "";
1460+
const std::string& label = data.exists("label") ? LabelFromValue(data["label"]) : "";
14611461

14621462
// Parse descriptor string
14631463
FlatSigningProvider keys;

src/wallet/rpc/transactions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ RPCHelpMan listtransactions()
487487

488488
std::optional<std::string> filter_label;
489489
if (!request.params[0].isNull() && request.params[0].get_str() != "*") {
490-
filter_label = request.params[0].get_str();
490+
filter_label.emplace(LabelFromValue(request.params[0]));
491491
if (filter_label.value().empty()) {
492492
throw JSONRPCError(RPC_INVALID_PARAMETER, "Label argument must be a valid label name or \"*\".");
493493
}
@@ -637,7 +637,7 @@ RPCHelpMan listsinceblock()
637637

638638
std::optional<std::string> filter_label;
639639
if (!request.params[5].isNull()) {
640-
filter_label = request.params[5].get_str();
640+
filter_label = LabelFromValue(request.params[5]);
641641
}
642642

643643
int depth = height ? wallet.GetLastBlockHeight() + 1 - *height : -1;

0 commit comments

Comments
 (0)