diff options
author | Sebastian Falbesoner <sebastian.falbesoner@gmail.com> | 2022-05-11 15:34:27 +0200 |
---|---|---|
committer | Sebastian Falbesoner <sebastian.falbesoner@gmail.com> | 2022-05-11 16:03:40 +0200 |
commit | 9feb887082be911a8342f8090af4dca3db76db9b (patch) | |
tree | 87785823ac5b38259936ba1e07986d3f44e826a5 /src/rpc/blockchain.cpp | |
parent | b8ded26ef3d7c58a938050659e4c50d850628dff (diff) | |
download | bitcoin-9feb887082be911a8342f8090af4dca3db76db9b.tar.xz |
rpc: check `fopen` return code in dumptxoutset
This change improves the usability of the `dumptxoutset` RPC in two ways,
in the case that an invalid path is passed:
1. return from the RPC immediately, rather then when the file is first
tried to be written (which is _after_ calculating the UTXO set hash)
2. return a proper return code and error message instead of the cryptic
"CAutoFile::operator<<: file handle is nullptr: unspecified
iostream_category error" (-1)
Diffstat (limited to 'src/rpc/blockchain.cpp')
-rw-r--r-- | src/rpc/blockchain.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 57b5178d78..50bf764e53 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -2281,6 +2281,12 @@ static RPCHelpMan dumptxoutset() FILE* file{fsbridge::fopen(temppath, "wb")}; CAutoFile afile{file, SER_DISK, CLIENT_VERSION}; + if (afile.IsNull()) { + throw JSONRPCError( + RPC_INVALID_PARAMETER, + "Couldn't open file " + temppath.u8string() + " for writing."); + } + NodeContext& node = EnsureAnyNodeContext(request.context); UniValue result = CreateUTXOSnapshot( node, node.chainman->ActiveChainstate(), afile, path, temppath); |