From 09184fc89cdcf2f1987078c9527f510061879836 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Wed, 4 Oct 2017 14:53:26 +0200 Subject: [PATCH] Merge #10939: [init] Check non-emptiness of -blocknotify command prior to executing cffe85f Skip sys::system(...) call in case of empty command (practicalswift) 6fb8f5f Check that -blocknotify command is non-empty before executing (practicalswift) Pull request description: Check that `-blocknotify` command is non-empty before executing. To make the `BlockNotifyCallback(...)` (`-blocknotify`) behaviour consistent with that of: * `AlertNotify(...)` (`-alertnotify`) * `AddToWallet(...)` (`-walletnotify`) Tree-SHA512: 18272166793a5a8b9cc2a727bfbcea53d38c329a55bc975c02db601329d608a61c20e026ce4b616193ecd3810dca4d3e2cb3bf773898a51872008a8dba96763e --- src/init.cpp | 7 ++++--- src/util.cpp | 1 + src/wallet/wallet.cpp | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index e64bc18f05fea..98aeca8881724 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -670,9 +670,10 @@ static void BlockNotifyCallback(bool initialSync, const CBlockIndex *pBlockIndex return; std::string strCmd = gArgs.GetArg("-blocknotify", ""); - - boost::replace_all(strCmd, "%s", pBlockIndex->GetBlockHash().GetHex()); - boost::thread t(runCommand, strCmd); // thread runs free + if (!strCmd.empty()) { + boost::replace_all(strCmd, "%s", pBlockIndex->GetBlockHash().GetHex()); + boost::thread t(runCommand, strCmd); // thread runs free + } } static bool fHaveGenesis = false; diff --git a/src/util.cpp b/src/util.cpp index 7c691d36e4ab4..48ca8a7ad91ac 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -934,6 +934,7 @@ fs::path GetSpecialFolderPath(int nFolder, bool fCreate) void runCommand(const std::string& strCommand) { + if (strCommand.empty()) return; int nErr = ::system(strCommand.c_str()); if (nErr) LogPrintf("runCommand error: system(%s) returned %d\n", strCommand, nErr); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index a158d4704309f..6e26a8ef3e21e 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1117,7 +1117,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose) // notify an external script when a wallet transaction comes in or is updated std::string strCmd = gArgs.GetArg("-walletnotify", ""); - if ( !strCmd.empty()) + if (!strCmd.empty()) { boost::replace_all(strCmd, "%s", wtxIn.GetHash().GetHex()); boost::thread t(runCommand, strCmd); // thread runs free