From e1a55690e66ca962179bc8170695b92af8a3caa8 Mon Sep 17 00:00:00 2001 From: Gregory Sanders Date: Fri, 31 May 2019 10:01:15 -0400 Subject: [PATCH] Delete error-prone CScript constructor --- src/qt/coincontroldialog.cpp | 6 ++++-- src/script/interpreter.cpp | 4 ++-- src/script/script.h | 4 +++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/qt/coincontroldialog.cpp b/src/qt/coincontroldialog.cpp index 6c9bae767..d5dd62178 100644 --- a/src/qt/coincontroldialog.cpp +++ b/src/qt/coincontroldialog.cpp @@ -422,7 +422,8 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog) if (amount > 0) { - CTxOut txout(amount, static_cast(std::vector(24, 0))); + // Assumes a p2pkh script size + CTxOut txout(amount, CScript() << std::vector(24, 0)); txDummy.vout.push_back(txout); fDust |= IsDust(txout, model->node().getDustRelayFee()); } @@ -513,7 +514,8 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog) // Never create dust outputs; if we would, just add the dust to the fee. if (nChange > 0 && nChange < MIN_CHANGE) { - CTxOut txout(nChange, static_cast(std::vector(24, 0))); + // Assumes a p2pkh script size + CTxOut txout(nChange, CScript() << std::vector(24, 0)); if (IsDust(txout, model->node().getDustRelayFee())) { nPayFee += nChange; diff --git a/src/script/interpreter.cpp b/src/script/interpreter.cpp index 95b25b491..f8701b6d0 100644 --- a/src/script/interpreter.cpp +++ b/src/script/interpreter.cpp @@ -926,7 +926,7 @@ bool EvalScript(std::vector >& stack, const CScript& // Drop the signature in pre-segwit scripts but not segwit scripts if (sigversion == SigVersion::BASE) { - int found = FindAndDelete(scriptCode, CScript(vchSig)); + int found = FindAndDelete(scriptCode, CScript() << vchSig); if (found > 0 && (flags & SCRIPT_VERIFY_CONST_SCRIPTCODE)) return set_error(serror, SCRIPT_ERR_SIG_FINDANDDELETE); } @@ -992,7 +992,7 @@ bool EvalScript(std::vector >& stack, const CScript& { valtype& vchSig = stacktop(-isig-k); if (sigversion == SigVersion::BASE) { - int found = FindAndDelete(scriptCode, CScript(vchSig)); + int found = FindAndDelete(scriptCode, CScript() << vchSig); if (found > 0 && (flags & SCRIPT_VERIFY_CONST_SCRIPTCODE)) return set_error(serror, SCRIPT_ERR_SIG_FINDANDDELETE); } diff --git a/src/script/script.h b/src/script/script.h index 11e8661a5..6355b8a70 100644 --- a/src/script/script.h +++ b/src/script/script.h @@ -437,7 +437,9 @@ public: explicit CScript(opcodetype b) { operator<<(b); } explicit CScript(const CScriptNum& b) { operator<<(b); } - explicit CScript(const std::vector& b) { operator<<(b); } + // delete non-existent constructor to defend against future introduction + // e.g. via prevector + explicit CScript(const std::vector& b) = delete; CScript& operator<<(int64_t b) { return push_int64(b); }