From 6fb8f5f17c079a7d32c855eae313c740e5f9e6be Mon Sep 17 00:00:00 2001 From: practicalswift Date: Thu, 27 Jul 2017 01:09:05 +0200 Subject: [PATCH 1/2] Check that -blocknotify command is non-empty before executing To make BlockNotifyCallback(...) (-blocknotify) consistent with: * AlertNotify(...) (-alertnotify) * AddToWallet(...) (-walletnotify) --- src/init.cpp | 7 ++++--- src/wallet/wallet.cpp | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index d79c2967b97e2..873a87c009d9e 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -547,9 +547,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/wallet/wallet.cpp b/src/wallet/wallet.cpp index 599e74149c500..41ecec9b6b76a 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -988,7 +988,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 From cffe85f975413441b8fbc5bda82fd2c9d75476f5 Mon Sep 17 00:00:00 2001 From: practicalswift Date: Thu, 27 Jul 2017 11:35:01 +0200 Subject: [PATCH 2/2] Skip sys::system(...) call in case of empty command --- src/util.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/util.cpp b/src/util.cpp index ba563478fada1..be76f2696f306 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -812,6 +812,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);