diff options
author | Andrew Chow <github@achow101.com> | 2023-01-10 17:22:21 -0500 |
---|---|---|
committer | Andrew Chow <github@achow101.com> | 2023-01-10 17:31:19 -0500 |
commit | 68f88bc03f2d4c908a064394795a045b1ac67c37 (patch) | |
tree | 7ae97cd8ea88751b5a313cec90eac09c864a564c /src/wallet/rpc/transactions.cpp | |
parent | b264410e012a61b103e1a03c43df4e17b9b75452 (diff) | |
parent | 65e78bda7cd23ad7b6ede63c6bf5ffe6f552c71d (diff) | |
download | bitcoin-68f88bc03f2d4c908a064394795a045b1ac67c37.tar.xz |
Merge bitcoin/bitcoin#26186: rpc: Sanitize label name in various RPCs with tests
65e78bda7cd23ad7b6ede63c6bf5ffe6f552c71d test: Invalid label name coverage (Aurèle Oulès)
552b51e682b5a52d9e2fbe64e44e623451692bd3 refactor: Add sanity checks in LabelFromValue (Aurèle Oulès)
67e7ba8e1aea58fc864f9bb1fc0e56b70777185e rpc: Sanitize label name in various RPCs (Aurèle Oulès)
Pull request description:
The following RPCs did not sanitize the optional label name:
- importprivkey
- importaddress
- importpubkey
- importmulti
- importdescriptors
- listsinceblock
Thus is was possible to import an address with a label `*` which should not be possible.
The wildcard label is used for backwards compatibility in the `listtransactions` rpc.
I added test coverage for these RPCs.
ACKs for top commit:
ajtowns:
ACK 65e78bda7cd23ad7b6ede63c6bf5ffe6f552c71d
achow101:
ACK 65e78bda7cd23ad7b6ede63c6bf5ffe6f552c71d
furszy:
diff ACK 65e78bd
stickies-v:
re-ACK 65e78bda7cd23ad7b6ede63c6bf5ffe6f552c71d
theStack:
re-ACK 65e78bda7cd23ad7b6ede63c6bf5ffe6f552c71d
Tree-SHA512: ad99f2824d4cfae352166b76da4ca0069b7c2eccf81aaa0654be25bbb3c6e5d6b005d93960f3f4154155f80e12be2d0cebd5529922ae3d2a36ee4eed82440b31
Diffstat (limited to 'src/wallet/rpc/transactions.cpp')
-rw-r--r-- | src/wallet/rpc/transactions.cpp | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/src/wallet/rpc/transactions.cpp b/src/wallet/rpc/transactions.cpp index c257af13c4..f571f8bcb2 100644 --- a/src/wallet/rpc/transactions.cpp +++ b/src/wallet/rpc/transactions.cpp @@ -486,7 +486,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 \"*\"."); } @@ -634,10 +634,9 @@ RPCHelpMan listsinceblock() bool include_removed = (request.params[3].isNull() || request.params[3].get_bool()); bool include_change = (!request.params[4].isNull() && request.params[4].get_bool()); + // Only set it if 'label' was provided. std::optional<std::string> filter_label; - if (!request.params[5].isNull()) { - filter_label = request.params[5].get_str(); - } + if (!request.params[5].isNull()) filter_label.emplace(LabelFromValue(request.params[5])); int depth = height ? wallet.GetLastBlockHeight() + 1 - *height : -1; |