Skip to content

Commit

Permalink
Merge pull request #213 from fireice-uk/ccx-fixes
Browse files Browse the repository at this point in the history
Implement a sanity limit on blocks and txes
  • Loading branch information
krypt0x authored Oct 21, 2021
2 parents 5c8d40d + 3e9f9a1 commit 2b15e4a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/CryptoNoteConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ namespace CryptoNote
const size_t BLOCKS_IDS_SYNCHRONIZING_DEFAULT_COUNT = 10000; // by default, blocks ids count in synchronizing
const size_t BLOCKS_SYNCHRONIZING_DEFAULT_COUNT = 128; // by default, blocks count in blocks downloading
const size_t COMMAND_RPC_GET_BLOCKS_FAST_MAX_COUNT = 1000;
const size_t COMMAND_RPC_GET_OBJECTS_MAX_COUNT = 1000;

const int P2P_DEFAULT_PORT = 15000;
const int RPC_DEFAULT_PORT = 16000;
Expand Down Expand Up @@ -282,4 +283,4 @@ namespace CryptoNote

} // namespace CryptoNote

#define ALLOW_DEBUG_COMMANDS
#define ALLOW_DEBUG_COMMANDS
8 changes: 8 additions & 0 deletions src/CryptoNoteProtocol/CryptoNoteProtocolHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,11 +395,19 @@ int CryptoNoteProtocolHandler::handle_notify_new_transactions(int command, NOTIF
int CryptoNoteProtocolHandler::handle_request_get_objects(int command, NOTIFY_REQUEST_GET_OBJECTS::request &arg, CryptoNoteConnectionContext &context)
{
logger(Logging::TRACE) << context << "NOTIFY_REQUEST_GET_OBJECTS";
if(arg.blocks.size() > COMMAND_RPC_GET_OBJECTS_MAX_COUNT || arg.txs.size() > COMMAND_RPC_GET_OBJECTS_MAX_COUNT)
{
logger(Logging::ERROR) << context << "GET_OBJECTS_MAX_COUNT exceeded blocks: " << arg.blocks.size() << " txes: " << arg.txs.size();
context.m_state = CryptoNoteConnectionContext::state_shutdown;
return 1;
}

NOTIFY_RESPONSE_GET_OBJECTS::request rsp;
if (!m_core.handle_get_objects(arg, rsp))
{
logger(Logging::ERROR) << context << "failed to handle request NOTIFY_REQUEST_GET_OBJECTS, dropping connection";
context.m_state = CryptoNoteConnectionContext::state_shutdown;
return 1;
}
logger(Logging::TRACE) << context << "-->>NOTIFY_RESPONSE_GET_OBJECTS: blocks.size()=" << rsp.blocks.size() << ", txs.size()=" << rsp.txs.size()
<< ", rsp.m_current_blockchain_height=" << rsp.current_blockchain_height << ", missed_ids.size()=" << rsp.missed_ids.size();
Expand Down

0 comments on commit 2b15e4a

Please sign in to comment.