Browse Source

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
0.16
Wladimir J. van der Laan 7 years ago
parent
commit
a1f7f18709
No known key found for this signature in database
GPG Key ID: 1E4AED62986CD25D
  1. 3
      src/init.cpp
  2. 1
      src/util.cpp
  3. 2
      src/wallet/wallet.cpp

3
src/init.cpp

@ -537,9 +537,10 @@ static void BlockNotifyCallback(bool initialSync, const CBlockIndex *pBlockIndex
return; return;
std::string strCmd = gArgs.GetArg("-blocknotify", ""); std::string strCmd = gArgs.GetArg("-blocknotify", "");
if (!strCmd.empty()) {
boost::replace_all(strCmd, "%s", pBlockIndex->GetBlockHash().GetHex()); boost::replace_all(strCmd, "%s", pBlockIndex->GetBlockHash().GetHex());
boost::thread t(runCommand, strCmd); // thread runs free boost::thread t(runCommand, strCmd); // thread runs free
}
} }
static bool fHaveGenesis = false; static bool fHaveGenesis = false;

1
src/util.cpp

@ -810,6 +810,7 @@ fs::path GetSpecialFolderPath(int nFolder, bool fCreate)
void runCommand(const std::string& strCommand) void runCommand(const std::string& strCommand)
{ {
if (strCommand.empty()) return;
int nErr = ::system(strCommand.c_str()); int nErr = ::system(strCommand.c_str());
if (nErr) if (nErr)
LogPrintf("runCommand error: system(%s) returned %d\n", strCommand, nErr); LogPrintf("runCommand error: system(%s) returned %d\n", strCommand, nErr);

2
src/wallet/wallet.cpp

@ -962,7 +962,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose)
// notify an external script when a wallet transaction comes in or is updated // notify an external script when a wallet transaction comes in or is updated
std::string strCmd = gArgs.GetArg("-walletnotify", ""); std::string strCmd = gArgs.GetArg("-walletnotify", "");
if ( !strCmd.empty()) if (!strCmd.empty())
{ {
boost::replace_all(strCmd, "%s", wtxIn.GetHash().GetHex()); boost::replace_all(strCmd, "%s", wtxIn.GetHash().GetHex());
boost::thread t(runCommand, strCmd); // thread runs free boost::thread t(runCommand, strCmd); // thread runs free

Loading…
Cancel
Save