aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorGavin Andresen <gavinandresen@gmail.com>2013-08-06 17:11:48 -0700
committerGavin Andresen <gavinandresen@gmail.com>2013-08-06 17:11:48 -0700
commitddd0e2f616be82fb57d68298be796c34268c6ae9 (patch)
tree6b96f78d0c90b1b59718100f76c98b5230bacb39 /src/test
parent1188a33d184bc6827ac7fb7839d9c5d7cb5676cf (diff)
parent159bc4819304c4394a92230c9e7b9f3416abe877 (diff)
Merge pull request #2871 from gavinandresen/simplify_maporphan
Simplify storage of orphan transactions, fix CVE-2013-4627
Diffstat (limited to 'src/test')
-rw-r--r--src/test/DoS_tests.cpp29
1 files changed, 9 insertions, 20 deletions
diff --git a/src/test/DoS_tests.cpp b/src/test/DoS_tests.cpp
index ea0cc1bcef..c7f968da7c 100644
--- a/src/test/DoS_tests.cpp
+++ b/src/test/DoS_tests.cpp
@@ -17,10 +17,10 @@
#include <stdint.h>
// Tests this internal-to-main.cpp method:
-extern bool AddOrphanTx(const CDataStream& vMsg);
+extern bool AddOrphanTx(const CTransaction& tx);
extern unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans);
-extern std::map<uint256, CDataStream*> mapOrphanTransactions;
-extern std::map<uint256, std::map<uint256, CDataStream*> > mapOrphanTransactionsByPrev;
+extern std::map<uint256, CTransaction> mapOrphanTransactions;
+extern std::map<uint256, std::set<uint256> > mapOrphanTransactionsByPrev;
CService ip(uint32_t i)
{
@@ -134,14 +134,11 @@ BOOST_AUTO_TEST_CASE(DoS_checknbits)
CTransaction RandomOrphan()
{
- std::map<uint256, CDataStream*>::iterator it;
+ std::map<uint256, CTransaction>::iterator it;
it = mapOrphanTransactions.lower_bound(GetRandHash());
if (it == mapOrphanTransactions.end())
it = mapOrphanTransactions.begin();
- const CDataStream* pvMsg = it->second;
- CTransaction tx;
- CDataStream(*pvMsg) >> tx;
- return tx;
+ return it->second;
}
BOOST_AUTO_TEST_CASE(DoS_mapOrphans)
@@ -163,9 +160,7 @@ BOOST_AUTO_TEST_CASE(DoS_mapOrphans)
tx.vout[0].nValue = 1*CENT;
tx.vout[0].scriptPubKey.SetDestination(key.GetPubKey().GetID());
- CDataStream ds(SER_DISK, CLIENT_VERSION);
- ds << tx;
- AddOrphanTx(ds);
+ AddOrphanTx(tx);
}
// ... and 50 that depend on other orphans:
@@ -182,9 +177,7 @@ BOOST_AUTO_TEST_CASE(DoS_mapOrphans)
tx.vout[0].scriptPubKey.SetDestination(key.GetPubKey().GetID());
SignSignature(keystore, txPrev, tx, 0);
- CDataStream ds(SER_DISK, CLIENT_VERSION);
- ds << tx;
- AddOrphanTx(ds);
+ AddOrphanTx(tx);
}
// This really-big orphan should be ignored:
@@ -208,9 +201,7 @@ BOOST_AUTO_TEST_CASE(DoS_mapOrphans)
for (unsigned int j = 1; j < tx.vin.size(); j++)
tx.vin[j].scriptSig = tx.vin[0].scriptSig;
- CDataStream ds(SER_DISK, CLIENT_VERSION);
- ds << tx;
- BOOST_CHECK(!AddOrphanTx(ds));
+ BOOST_CHECK(!AddOrphanTx(tx));
}
// Test LimitOrphanTxSize() function:
@@ -247,9 +238,7 @@ BOOST_AUTO_TEST_CASE(DoS_checkSig)
tx.vout[0].nValue = 1*CENT;
tx.vout[0].scriptPubKey.SetDestination(key.GetPubKey().GetID());
- CDataStream ds(SER_DISK, CLIENT_VERSION);
- ds << tx;
- AddOrphanTx(ds);
+ AddOrphanTx(tx);
}
// Create a transaction that depends on orphans: