aboutsummaryrefslogtreecommitdiff
path: root/contrib/epee/include
diff options
context:
space:
mode:
authorAlexander Blair <snipa@jagtech.io>2020-08-16 12:55:24 -0700
committerAlexander Blair <snipa@jagtech.io>2020-08-16 12:55:25 -0700
commitd73b1b6560a51a052b796f4dcd4e6778ef285d1f (patch)
tree01116d96637d76a8bf562c786b96a63642d63ec7 /contrib/epee/include
parentMerge pull request #6722 (diff)
parentrpc: reject wrong sized txid (diff)
downloadmonero-d73b1b6560a51a052b796f4dcd4e6778ef285d1f.tar.xz
Merge pull request #6727
13eee1d6a rpc: reject wrong sized txid (moneromooo-monero) 92e6b7df2 easylogging++: fix crash with reentrant logging (moneromooo-monero) 6dd95d530 epee: guard against exceptions in RPC handlers (moneromooo-monero) 90016ad74 blockchain: guard against exceptions in add_new_block/children (moneromooo-monero)
Diffstat (limited to 'contrib/epee/include')
-rw-r--r--contrib/epee/include/net/http_server_handlers_map2.h40
1 files changed, 31 insertions, 9 deletions
diff --git a/contrib/epee/include/net/http_server_handlers_map2.h b/contrib/epee/include/net/http_server_handlers_map2.h
index 0c0653cd6..ac22cd7a9 100644
--- a/contrib/epee/include/net/http_server_handlers_map2.h
+++ b/contrib/epee/include/net/http_server_handlers_map2.h
@@ -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"; \