From 6996a9d7131cc634cb67dcd56a71ca9744001c8f Mon Sep 17 00:00:00 2001 From: Gavin Andresen Date: Sun, 25 Dec 2011 08:45:09 -0500 Subject: [PATCH] Check for valid prevout.n in FetchInputs. IsStandardInputs could crash if given invalid input index. --- src/main.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 161a9a91..725fabff 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -284,6 +284,7 @@ bool CTransaction::AreInputsStandard(std::map 0); CTransaction& txPrev = mapInputs[prevout.hash].second; + assert(prevout.n >= txPrev.vout.size()); vector > vSolutions; txnouttype whichType; @@ -944,6 +945,9 @@ bool CTransaction::FetchInputs(CTxDB& txdb, const map& mapTes if (!txPrev.ReadFromDisk(txindex.pos)) return error("FetchInputs() : %s ReadFromDisk prev tx %s failed", GetHash().ToString().substr(0,10).c_str(), prevout.hash.ToString().substr(0,10).c_str()); } + if (prevout.n >= txPrev.vout.size() || prevout.n >= txindex.vSpent.size()) + 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; }