aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bitcoinrpc.cpp5
-rw-r--r--src/main.cpp26
-rw-r--r--src/main.h3
3 files changed, 26 insertions, 8 deletions
diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp
index 5ac58de06d..3063abd1fa 100644
--- a/src/bitcoinrpc.cpp
+++ b/src/bitcoinrpc.cpp
@@ -1025,9 +1025,12 @@ Value addmultisigaddress(const Array& params, bool fHelp)
if (address.IsScript())
throw runtime_error(
strprintf("%s is a pay-to-script address",ks.c_str()));
- if (!pwalletMain->GetKey(address, pubkeys[i]))
+ std::vector<unsigned char> vchPubKey;
+ if (!pwalletMain->GetPubKey(address, vchPubKey))
throw runtime_error(
strprintf("no full public key for address %s",ks.c_str()));
+ if (vchPubKey.empty() || !pubkeys[i].SetPubKey(vchPubKey))
+ throw runtime_error(" Invalid public key: "+ks);
}
// Case 2: hex public key
diff --git a/src/main.cpp b/src/main.cpp
index a19cf0e33e..e242fa640d 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -489,8 +489,11 @@ bool CTransaction::AcceptToMemoryPool(CTxDB& txdb, bool fCheckInputs, bool* pfMi
{
MapPrevTx mapInputs;
map<uint256, CTxIndex> mapUnused;
- if (!FetchInputs(txdb, mapUnused, false, false, mapInputs))
+ bool fInvalid = false;
+ if (!FetchInputs(txdb, mapUnused, false, false, mapInputs, fInvalid))
{
+ if (fInvalid)
+ return error("AcceptToMemoryPool() : FetchInputs found invalid tx %s", hash.ToString().substr(0,10).c_str());
if (pfMissingInputs)
*pfMissingInputs = true;
return error("AcceptToMemoryPool() : FetchInputs failed %s", hash.ToString().substr(0,10).c_str());
@@ -543,8 +546,6 @@ bool CTransaction::AcceptToMemoryPool(CTxDB& txdb, bool fCheckInputs, bool* pfMi
// This is done last to help prevent CPU exhaustion denial-of-service attacks.
if (!ConnectInputs(mapInputs, mapUnused, CDiskTxPos(1,1,1), pindexBest, false, false))
{
- if (pfMissingInputs)
- *pfMissingInputs = true;
return error("AcceptToMemoryPool() : ConnectInputs failed %s", hash.ToString().substr(0,10).c_str());
}
}
@@ -920,8 +921,14 @@ bool CTransaction::DisconnectInputs(CTxDB& txdb)
bool CTransaction::FetchInputs(CTxDB& txdb, const map<uint256, CTxIndex>& mapTestPool,
- bool fBlock, bool fMiner, MapPrevTx& inputsRet)
+ bool fBlock, bool fMiner, MapPrevTx& inputsRet, bool& fInvalid)
{
+ // FetchInputs can return false either because we just haven't seen some inputs
+ // (in which case the transaction should be stored as an orphan)
+ // or because the transaction is malformed (in which case the transaction should
+ // be dropped). If tx is definitely invalid, fInvalid will be set to true.
+ fInvalid = false;
+
if (IsCoinBase())
return true; // Coinbase transactions have no inputs to fetch.
@@ -977,7 +984,12 @@ bool CTransaction::FetchInputs(CTxDB& txdb, const map<uint256, CTxIndex>& mapTes
const CTxIndex& txindex = inputsRet[prevout.hash].first;
const CTransaction& txPrev = inputsRet[prevout.hash].second;
if (prevout.n >= txPrev.vout.size() || prevout.n >= txindex.vSpent.size())
+ {
+ // Revisit this if/when transaction replacement is implemented and allows
+ // adding inputs:
+ fInvalid = true;
return DoS(100, error("FetchInputs() : %s prevout.n out of range %d %d %d prev tx %s\n%s", GetHash().ToString().substr(0,10).c_str(), prevout.n, txPrev.vout.size(), txindex.vSpent.size(), prevout.hash.ToString().substr(0,10).c_str(), txPrev.ToString().c_str()));
+ }
}
return true;
@@ -1200,7 +1212,8 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex)
MapPrevTx mapInputs;
if (!tx.IsCoinBase())
{
- if (!tx.FetchInputs(txdb, mapQueuedChanges, true, false, mapInputs))
+ bool fInvalid;
+ if (!tx.FetchInputs(txdb, mapQueuedChanges, true, false, mapInputs, fInvalid))
return false;
int nTxOps = tx.GetSigOpCount(mapInputs);
@@ -3060,7 +3073,8 @@ CBlock* CreateNewBlock(CReserveKey& reservekey)
// because we're already processing them in order of dependency
map<uint256, CTxIndex> mapTestPoolTmp(mapTestPool);
MapPrevTx mapInputs;
- if (!tx.FetchInputs(txdb, mapTestPoolTmp, false, true, mapInputs))
+ bool fInvalid;
+ if (!tx.FetchInputs(txdb, mapTestPoolTmp, false, true, mapInputs, fInvalid))
continue;
int64 nFees = tx.GetValueIn(mapInputs)-tx.GetValueOut();
diff --git a/src/main.h b/src/main.h
index be5f2f58a5..ec5623d17d 100644
--- a/src/main.h
+++ b/src/main.h
@@ -684,10 +684,11 @@ public:
@param[in] fBlock True if being called to add a new best-block to the chain
@param[in] fMiner True if being called by CreateNewBlock
@param[out] inputsRet Pointers to this transaction's inputs
+ @param[out] fInvalid returns true if transaction is invalid
@return Returns true if all inputs are in txdb or mapTestPool
*/
bool FetchInputs(CTxDB& txdb, const std::map<uint256, CTxIndex>& mapTestPool,
- bool fBlock, bool fMiner, MapPrevTx& inputsRet);
+ bool fBlock, bool fMiner, MapPrevTx& inputsRet, bool& fInvalid);
/** Sanity check previous transactions, then, if all checks succeed,
mark them as spent by this transaction.