Skip to content

Commit e1a5569

Browse files
committed
Delete error-prone CScript constructor
1 parent c7cfd20 commit e1a5569

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

src/qt/coincontroldialog.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,8 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
422422

423423
if (amount > 0)
424424
{
425-
CTxOut txout(amount, static_cast<CScript>(std::vector<unsigned char>(24, 0)));
425+
// Assumes a p2pkh script size
426+
CTxOut txout(amount, CScript() << std::vector<unsigned char>(24, 0));
426427
txDummy.vout.push_back(txout);
427428
fDust |= IsDust(txout, model->node().getDustRelayFee());
428429
}
@@ -513,7 +514,8 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
513514
// Never create dust outputs; if we would, just add the dust to the fee.
514515
if (nChange > 0 && nChange < MIN_CHANGE)
515516
{
516-
CTxOut txout(nChange, static_cast<CScript>(std::vector<unsigned char>(24, 0)));
517+
// Assumes a p2pkh script size
518+
CTxOut txout(nChange, CScript() << std::vector<unsigned char>(24, 0));
517519
if (IsDust(txout, model->node().getDustRelayFee()))
518520
{
519521
nPayFee += nChange;

src/script/interpreter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,7 @@ bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript&
926926

927927
// Drop the signature in pre-segwit scripts but not segwit scripts
928928
if (sigversion == SigVersion::BASE) {
929-
int found = FindAndDelete(scriptCode, CScript(vchSig));
929+
int found = FindAndDelete(scriptCode, CScript() << vchSig);
930930
if (found > 0 && (flags & SCRIPT_VERIFY_CONST_SCRIPTCODE))
931931
return set_error(serror, SCRIPT_ERR_SIG_FINDANDDELETE);
932932
}
@@ -992,7 +992,7 @@ bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript&
992992
{
993993
valtype& vchSig = stacktop(-isig-k);
994994
if (sigversion == SigVersion::BASE) {
995-
int found = FindAndDelete(scriptCode, CScript(vchSig));
995+
int found = FindAndDelete(scriptCode, CScript() << vchSig);
996996
if (found > 0 && (flags & SCRIPT_VERIFY_CONST_SCRIPTCODE))
997997
return set_error(serror, SCRIPT_ERR_SIG_FINDANDDELETE);
998998
}

src/script/script.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,9 @@ class CScript : public CScriptBase
437437

438438
explicit CScript(opcodetype b) { operator<<(b); }
439439
explicit CScript(const CScriptNum& b) { operator<<(b); }
440-
explicit CScript(const std::vector<unsigned char>& b) { operator<<(b); }
440+
// delete non-existent constructor to defend against future introduction
441+
// e.g. via prevector
442+
explicit CScript(const std::vector<unsigned char>& b) = delete;
441443

442444

443445
CScript& operator<<(int64_t b) { return push_int64(b); }

0 commit comments

Comments
 (0)