aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2020-07-06 15:49:02 +0000
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2020-07-30 22:52:12 +0000
commit6dd95d5308548d62f9340d1f8bfc9ffa21e2eec8 (patch)
tree5fcbe76bb55354687080e313ec81d737ed5eb3d4
parentblockchain: guard against exceptions in add_new_block/children (diff)
downloadmonero-6dd95d5308548d62f9340d1f8bfc9ffa21e2eec8.tar.xz
epee: guard against exceptions in RPC handlers
-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"; \