Check earlier for blocks with duplicate transactions. Fixes #1167
authorGavin Andresen <gavinandresen@gmail.com>
Mon, 30 Apr 2012 00:56:55 +0000 (20:56 -0400)
committerLuke Dashjr <luke-jr+git@utopios.org>
Fri, 4 May 2012 18:52:16 +0000 (18:52 +0000)
src/main.cpp

index e6f9421..e8cbc01 100644 (file)
@@ -1472,6 +1472,16 @@ bool CBlock::CheckBlock() const
         if (!tx.CheckTransaction())
             return error("CheckBlock() : CheckTransaction failed");
 
+    // Check for duplicate txids. This is caught by ConnectInputs(),
+    // but catching it earlier avoids a potential DoS attack:
+    set<uint256> uniqueTx;
+    BOOST_FOREACH(const CTransaction& tx, vtx)
+    {
+        uniqueTx.insert(tx.GetHash());
+    }
+    if (uniqueTx.size() != vtx.size())
+        return error("CheckBlock() : duplicate transaction");
+
     // Check that it's not full of nonstandard transactions
     if (GetSigOpCount() > MAX_BLOCK_SIGOPS)
         return error("CheckBlock() : out-of-bounds SigOpCount");