From 5eef64578ba1e19c9a6045a25369db19d4136e75 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Fri, 25 Dec 2015 21:56:37 +0000 Subject: [PATCH] db: throw when given a non txout_to_key output to add The check was explicit in the original version, so it seems safer to make it explicit here, especially as it is now done implicitely in a different place, away from the original check. --- src/blockchain_db/berkeleydb/db_bdb.cpp | 4 ++++ src/blockchain_db/lmdb/db_lmdb.cpp | 4 ++++ src/cryptonote_core/blockchain.cpp | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/src/blockchain_db/berkeleydb/db_bdb.cpp b/src/blockchain_db/berkeleydb/db_bdb.cpp index 236bc4fe6..4799afebc 100644 --- a/src/blockchain_db/berkeleydb/db_bdb.cpp +++ b/src/blockchain_db/berkeleydb/db_bdb.cpp @@ -391,6 +391,10 @@ void BlockchainBDB::add_output(const crypto::hash& tx_hash, const tx_out& tx_out if (m_output_keys->put(DB_DEFAULT_TX, &k, &data, 0)) throw0(DB_ERROR("Failed to add output pubkey to db transaction")); } + else + { + throw0(DB_ERROR("Wrong output type: expected txout_to_key")); + } m_num_outputs++; } diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp index 4a4550179..b5f76301c 100644 --- a/src/blockchain_db/lmdb/db_lmdb.cpp +++ b/src/blockchain_db/lmdb/db_lmdb.cpp @@ -695,6 +695,10 @@ void BlockchainLMDB::add_output(const crypto::hash& tx_hash, const tx_out& tx_ou if (mdb_put(*m_write_txn, m_output_keys, &k, &data, 0)) throw0(DB_ERROR("Failed to add output pubkey to db transaction")); } + else + { + throw0(DB_ERROR("Wrong output type: expected txout_to_key")); + } m_num_outputs++; } diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index badccd06f..b83a5fd0e 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -2246,6 +2246,11 @@ bool Blockchain::check_tx_input(const txin_to_key& txin, const crypto::hash& tx_ return false; } + // The original code includes a check for the output corresponding to this input + // to be a txout_to_key. This is removed, as the database does not store this info, + // but only txout_to_key outputs are stored in the DB in the first place, done in + // Blockchain*::add_output + m_output_keys.push_back(pubkey); return true; }