diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2018-04-29 11:41:54 +0100 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2018-05-09 14:03:07 +0100 |
commit | b5cb1bc4034d10e254ddd3d1f6093853e1ba9517 (patch) | |
tree | eb70b2048aaac950b2e5646b32897dd502242847 | |
parent | Merge pull request #3775 (diff) | |
download | monero-b5cb1bc4034d10e254ddd3d1f6093853e1ba9517.tar.xz |
blockchain: avoid exception if asked for a block we do not have
This can happen if a peer tries to obtain the next span from other
peers if that span is needed for not downloaded yet. Also if the
peer maliciously requests a non existent block hash.
-rw-r--r-- | src/cryptonote_core/blockchain.cpp | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index 25e97f71f..65bee4d86 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -2032,16 +2032,19 @@ bool Blockchain::get_blocks(const t_ids_container& block_ids, t_blocks_container { try { - blocks.push_back(std::make_pair(m_db->get_block_blob(block_hash), block())); - if (!parse_and_validate_block_from_blob(blocks.back().first, blocks.back().second)) + uint64_t height = 0; + if (m_db->block_exists(block_hash, &height)) { - LOG_ERROR("Invalid block"); - return false; + blocks.push_back(std::make_pair(m_db->get_block_blob_from_height(height), block())); + if (!parse_and_validate_block_from_blob(blocks.back().first, blocks.back().second)) + { + LOG_ERROR("Invalid block: " << block_hash); + blocks.pop_back(); + missed_bs.push_back(block_hash); + } } - } - catch (const BLOCK_DNE& e) - { - missed_bs.push_back(block_hash); + else + missed_bs.push_back(block_hash); } catch (const std::exception& e) { |