Merge pull request #6728

870a7b5 rpc: reject wrong sized txid (moneromooo-monero)
5b761d0 easylogging++: fix crash with reentrant logging (moneromooo-monero)
c02d762 epee: guard against exceptions in RPC handlers (moneromooo-monero)
0678fc1 blockchain: guard against exceptions in add_new_block/children (moneromooo-monero)
This commit is contained in:
luigi1111 2020-07-31 15:05:03 -05:00
commit 7f8fe816f4
No known key found for this signature in database
GPG key ID: F4ACA0183641E010
4 changed files with 57 additions and 15 deletions

View file

@ -42,8 +42,17 @@
MINFO("HTTP [" << m_conn_context.m_remote_address.host_str() << "] " << query_info.m_http_method_str << " " << query_info.m_URI); \
response.m_response_code = 200; \
response.m_response_comment = "Ok"; \
if(!handle_http_request_map(query_info, response, m_conn_context)) \
{response.m_response_code = 404;response.m_response_comment = "Not found";} \
try \
{ \
if(!handle_http_request_map(query_info, response, m_conn_context)) \
{response.m_response_code = 404;response.m_response_comment = "Not found";} \
} \
catch (const std::exception &e) \
{ \
MERROR(m_conn_context << "Exception in handle_http_request_map: " << e.what()); \
response.m_response_code = 500; \
response.m_response_comment = "Internal Server Error"; \
} \
return true; \
}
@ -69,9 +78,11 @@
uint64_t ticks1 = epee::misc_utils::get_tick_count(); \
boost::value_initialized<command_type::response> resp;\
MINFO(m_conn_context << "calling " << s_pattern); \
if(!callback_f(static_cast<command_type::request&>(req), static_cast<command_type::response&>(resp), &m_conn_context)) \
bool res = false; \
try { res = callback_f(static_cast<command_type::request&>(req), static_cast<command_type::response&>(resp), &m_conn_context); } \
catch (const std::exception &e) { MERROR(m_conn_context << "Failed to " << #callback_f << "(): " << e.what()); } \
if (!res) \
{ \
MERROR(m_conn_context << "Failed to " << #callback_f << "()"); \
response_info.m_response_code = 500; \
response_info.m_response_comment = "Internal Server Error"; \
return true; \
@ -97,9 +108,11 @@
uint64_t ticks1 = misc_utils::get_tick_count(); \
boost::value_initialized<command_type::response> resp;\
MINFO(m_conn_context << "calling " << s_pattern); \
if(!callback_f(static_cast<command_type::request&>(req), static_cast<command_type::response&>(resp), &m_conn_context)) \
bool res = false; \
try { res = callback_f(static_cast<command_type::request&>(req), static_cast<command_type::response&>(resp), &m_conn_context); } \
catch (const std::exception &e) { MERROR(m_conn_context << "Failed to " << #callback_f << "()"); } \
if (!res) \
{ \
MERROR(m_conn_context << "Failed to " << #callback_f << "()"); \
response_info.m_response_code = 500; \
response_info.m_response_comment = "Internal Server Error"; \
return true; \
@ -184,7 +197,10 @@
fail_resp.jsonrpc = "2.0"; \
fail_resp.id = req.id; \
MINFO(m_conn_context << "Calling RPC method " << method_name); \
if(!callback_f(req.params, resp.result, fail_resp.error, &m_conn_context)) \
bool res = false; \
try { res = callback_f(req.params, resp.result, fail_resp.error, &m_conn_context); } \
catch (const std::exception &e) { MERROR(m_conn_context << "Failed to " << #callback_f << "(): " << e.what()); } \
if (!res) \
{ \
epee::serialization::store_t_to_json(static_cast<epee::json_rpc::error_response&>(fail_resp), response_info.m_body); \
return true; \
@ -203,7 +219,10 @@
fail_resp.jsonrpc = "2.0"; \
fail_resp.id = req.id; \
MINFO(m_conn_context << "calling RPC method " << method_name); \
if(!callback_f(req.params, resp.result, fail_resp.error, response_info, &m_conn_context)) \
bool res = false; \
try { res = callback_f(req.params, resp.result, fail_resp.error, response_info, &m_conn_context); } \
catch (const std::exception &e) { MERROR(m_conn_context << "Failed to " << #callback_f << "(): " << e.what()); } \
if (!res) \
{ \
epee::serialization::store_t_to_json(static_cast<epee::json_rpc::error_response&>(fail_resp), response_info.m_body); \
return true; \
@ -217,7 +236,10 @@
{ \
PREPARE_OBJECTS_FROM_JSON(command_type) \
MINFO(m_conn_context << "calling RPC method " << method_name); \
if(!callback_f(req.params, resp.result, &m_conn_context)) \
bool res = false; \
try { res = callback_f(req.params, resp.result, &m_conn_context); } \
catch (const std::exception &e) { MERROR(m_conn_context << "Failed to " << #callback_f << "(): " << e.what()); } \
if (!res) \
{ \
epee::json_rpc::error_response fail_resp = AUTO_VAL_INIT(fail_resp); \
fail_resp.jsonrpc = "2.0"; \

View file

@ -2968,6 +2968,16 @@ void Writer::initializeLogger(Logger *logger, bool needLock) {
}
void Writer::processDispatch() {
static std::atomic_flag in_dispatch;
if (in_dispatch.test_and_set())
{
if (m_proceed && m_logger != NULL)
{
m_logger->stream().str(ELPP_LITERAL(""));
m_logger->releaseLock();
}
return;
}
#if ELPP_LOGGING_ENABLED
if (ELPP->hasFlag(LoggingFlag::MultiLoggerSupport)) {
bool firstDispatched = false;
@ -3006,6 +3016,7 @@ void Writer::processDispatch() {
m_logger->releaseLock();
}
#endif // ELPP_LOGGING_ENABLED
in_dispatch.clear();
}
void Writer::triggerDispatch(void) {

View file

@ -4253,6 +4253,9 @@ bool Blockchain::update_next_cumulative_weight_limit(uint64_t *long_term_effecti
//------------------------------------------------------------------
bool Blockchain::add_new_block(const block& bl, block_verification_context& bvc)
{
try
{
LOG_PRINT_L3("Blockchain::" << __func__);
crypto::hash id = get_block_hash(bl);
CRITICAL_REGION_LOCAL(m_tx_pool);//to avoid deadlock lets lock tx_pool for whole add/reorganize process
@ -4280,6 +4283,14 @@ bool Blockchain::add_new_block(const block& bl, block_verification_context& bvc)
rtxn_guard.stop();
return handle_block_to_main_chain(bl, id, bvc);
}
catch (const std::exception &e)
{
LOG_ERROR("Exception at [add_new_block], what=" << e.what());
bvc.m_verifivation_failed = true;
return false;
}
}
//------------------------------------------------------------------
//TODO: Refactor, consider returning a failure height and letting

View file

@ -2453,14 +2453,13 @@ namespace cryptonote
{
for (const auto &str: req.txids)
{
cryptonote::blobdata txid_data;
if(!epee::string_tools::parse_hexstr_to_binbuff(str, txid_data))
crypto::hash txid;
if(!epee::string_tools::hex_to_pod(str, txid))
{
failed = true;
}
else
{
crypto::hash txid = *reinterpret_cast<const crypto::hash*>(txid_data.data());
txids.push_back(txid);
}
}
@ -2805,15 +2804,14 @@ namespace cryptonote
res.status = "";
for (const auto &str: req.txids)
{
cryptonote::blobdata txid_data;
if(!epee::string_tools::parse_hexstr_to_binbuff(str, txid_data))
crypto::hash txid;
if(!epee::string_tools::hex_to_pod(str, txid))
{
if (!res.status.empty()) res.status += ", ";
res.status += std::string("invalid transaction id: ") + str;
failed = true;
continue;
}
crypto::hash txid = *reinterpret_cast<const crypto::hash*>(txid_data.data());
cryptonote::blobdata txblob;
if (m_core.get_pool_transaction(txid, txblob, relay_category::legacy))