Skip to content

Commit

Permalink
Merge bitcoin#10939: [init] Check non-emptiness of -blocknotify comma…
Browse files Browse the repository at this point in the history
…nd 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
  • Loading branch information
laanwj authored and PastaPastaPasta committed Feb 9, 2020
1 parent fb18f26 commit 09184fc
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/init.cpp
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/util.cpp
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/wallet.cpp
Expand Up @@ -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
Expand Down

0 comments on commit 09184fc

Please sign in to comment.