Skip to content

Commit a1f7f18

Browse files
committed
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
2 parents e12522d + cffe85f commit a1f7f18

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

src/init.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -537,9 +537,10 @@ static void BlockNotifyCallback(bool initialSync, const CBlockIndex *pBlockIndex
537537
return;
538538

539539
std::string strCmd = gArgs.GetArg("-blocknotify", "");
540-
541-
boost::replace_all(strCmd, "%s", pBlockIndex->GetBlockHash().GetHex());
542-
boost::thread t(runCommand, strCmd); // thread runs free
540+
if (!strCmd.empty()) {
541+
boost::replace_all(strCmd, "%s", pBlockIndex->GetBlockHash().GetHex());
542+
boost::thread t(runCommand, strCmd); // thread runs free
543+
}
543544
}
544545

545546
static bool fHaveGenesis = false;

src/util.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,7 @@ fs::path GetSpecialFolderPath(int nFolder, bool fCreate)
810810

811811
void runCommand(const std::string& strCommand)
812812
{
813+
if (strCommand.empty()) return;
813814
int nErr = ::system(strCommand.c_str());
814815
if (nErr)
815816
LogPrintf("runCommand error: system(%s) returned %d\n", strCommand, nErr);

src/wallet/wallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose)
962962
// notify an external script when a wallet transaction comes in or is updated
963963
std::string strCmd = gArgs.GetArg("-walletnotify", "");
964964

965-
if ( !strCmd.empty())
965+
if (!strCmd.empty())
966966
{
967967
boost::replace_all(strCmd, "%s", wtxIn.GetHash().GetHex());
968968
boost::thread t(runCommand, strCmd); // thread runs free

0 commit comments

Comments
 (0)