Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Explicitly catch bad_alloc exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Timothy Banks committed Jul 21, 2020
1 parent 773acaf commit d99f933
Show file tree
Hide file tree
Showing 16 changed files with 153 additions and 4 deletions.
4 changes: 4 additions & 0 deletions libraries/chain/apply_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ void apply_context::exec_one()
} else {
act_digest = digest_type::hash(*act);
}
} catch ( const std::bad_alloc& ) {
throw;
} catch ( const boost::interprocess::bad_alloc& ) {
throw;
} catch( const fc::exception& e ) {
handle_exception(e);
} catch ( const std::exception& e ) {
Expand Down
20 changes: 20 additions & 0 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1219,6 +1219,10 @@ struct controller_impl {
return trace;
} catch( const objective_block_validation_exception& ) {
throw;
} catch ( const std::bad_alloc& ) {
throw;
} catch ( const boost::interprocess::bad_alloc& ) {
throw;
} catch( const fc::exception& e ) {
handle_exception(e);
} catch ( const std::exception& e ) {
Expand Down Expand Up @@ -1391,6 +1395,10 @@ struct controller_impl {
return trace;
} catch( const objective_block_validation_exception& ) {
throw;
} catch ( const std::bad_alloc& ) {
throw;
} catch ( const boost::interprocess::bad_alloc& ) {
throw;
} catch( const fc::exception& e ) {
handle_exception(e);
} catch ( const std::exception& e) {
Expand Down Expand Up @@ -1604,6 +1612,10 @@ struct controller_impl {
return trace;
} catch( const objective_block_validation_exception& ) {
throw;
} catch ( const std::bad_alloc& ) {
throw;
} catch ( const boost::interprocess::bad_alloc& ) {
throw;
} catch (const fc::exception& e) {
handle_exception(e);
} catch (const std::exception& e) {
Expand Down Expand Up @@ -2051,6 +2063,10 @@ struct controller_impl {

commit_block(false);
return;
} catch ( const std::bad_alloc& ) {
throw;
} catch ( const boost::interprocess::bad_alloc& ) {
throw;
} catch ( const fc::exception& e ) {
edump((e.to_detail_string()));
abort_block();
Expand Down Expand Up @@ -2237,6 +2253,10 @@ struct controller_impl {
: controller::block_status::complete, trx_lookup );
fork_db.mark_valid( *ritr );
head = *ritr;
} catch ( const std::bad_alloc& ) {
throw;
} catch ( const boost::interprocess::bad_alloc& ) {
throw;
} catch (const fc::exception& e) {
elog("exception thrown while switching forks ${e}", ("e", e.to_detail_string()));
except = std::current_exception();
Expand Down
8 changes: 8 additions & 0 deletions libraries/fc/src/network/ntp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ namespace fc
{
throw;
}
catch ( const std::bad_alloc& )
{
throw;
}
catch ( const boost::interprocess::bad_alloc& )
{
throw;
}
// this could fail to resolve but we want to go on to other hosts..
catch ( const fc::exception& e )
{
Expand Down
8 changes: 8 additions & 0 deletions libraries/fc/src/network/udt_socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ namespace fc {
{
try {
close();
} catch ( const std::bad_alloc& ) {
throw;
} catch ( const boost::interprocess::bad_alloc& ) {
throw;
} catch ( const fc::exception& e ) {
wlog( "${e}", ("e", e.to_detail_string() ) );
} catch ( const std::exception& e ) {
Expand Down Expand Up @@ -338,6 +342,10 @@ namespace fc {
{
try {
close();
} catch ( const std::bad_alloc& ) {
throw;
} catch ( const boost::interprocess::bad_alloc& ) {
throw;
} catch ( const fc::exception& e ) {
wlog( "${e}", ("e", e.to_detail_string() ) );
} catch ( const std::exception& e ) {
Expand Down
8 changes: 8 additions & 0 deletions libraries/fc/src/rpc/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ void cli::run()
else
std::cout << itr->second( result, args ) << "\n";
}
catch ( const std::bad_alloc& )
{
throw;
}
catch ( const boost::interprocess::bad_alloc& )
{
throw;
}
catch ( const fc::exception& e )
{
std::cout << e.to_detail_string() << "\n";
Expand Down
24 changes: 24 additions & 0 deletions libraries/fc/src/rpc/http_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ void http_api_connection::on_request( const fc::http::request& req, const fc::ht
resp_body = fc::json::to_string( fc::rpc::response( *call.id, result ) );
resp_status = http::reply::OK;
}
catch ( const std::bad_alloc& )
{
throw;
}
catch ( const boost::interprocess::bad_alloc& )
{
throw;
}
catch ( const fc::exception& e )
{
handle_error_inner(e);
Expand All @@ -130,6 +138,14 @@ void http_api_connection::on_request( const fc::http::request& req, const fc::ht
resp_body = "";
}
}
catch ( const std::bad_alloc& )
{
throw;
}
catch ( const boost::interprocess::bad_alloc& )
{
throw;
}
catch ( const fc::exception& e )
{
handle_error(e);
Expand All @@ -145,6 +161,14 @@ void http_api_connection::on_request( const fc::http::request& req, const fc::ht
resp.set_length( resp_body.length() );
resp.write( resp_body.c_str(), resp_body.length() );
}
catch ( const std::bad_alloc& )
{
throw;
}
catch ( const boost::interprocess::bad_alloc& )
{
throw;
}
catch( const fc::exception& e )
{
wdump((e.to_detail_string()));
Expand Down
16 changes: 16 additions & 0 deletions libraries/fc/src/rpc/websocket_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ std::string websocket_api_connection::on_message(
return reply;
}
}
catch ( const std::bad_alloc& )
{
throw;
}
catch ( const boost::interprocess::bad_alloc& )
{
throw;
}
catch ( const fc::exception& e )
{
optexcept = handle_error_inner(e);
Expand All @@ -147,6 +155,14 @@ std::string websocket_api_connection::on_message(
_rpc_state.handle_reply( reply );
}
}
catch ( const std::bad_alloc& )
{
throw;
}
catch ( const boost::interprocess::bad_alloc& )
{
throw;
}
catch ( const fc::exception& e )
{
return handle_error(e);
Expand Down
4 changes: 4 additions & 0 deletions libraries/rodeos/rodeos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,10 @@ void rodeos_filter::process(rodeos_db_snapshot& snapshot, const ship_protocol::g
} catch (...) {
try {
throw;
} catch ( const std::bad_alloc& ) {
throw;
} catch ( const boost::interprocess::bad_alloc& ) {
throw;
} catch( const fc::exception& e ) {
elog( "fc::exception processing filter wasm: ${e}", ("e", e.to_detail_string()) );
} catch( const std::exception& e ) {
Expand Down
4 changes: 4 additions & 0 deletions plugins/faucet_testnet_plugin/faucet_testnet_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ void faucet_testnet_plugin::plugin_startup() {
void faucet_testnet_plugin::plugin_shutdown() {
try {
my->_timer.cancel();
} catch ( const std::bad_alloc& ) {
throw;
} catch ( const boost::interprocess::bad_alloc& ) {
throw;
} catch(const fc::exception& e) {
edump((e.to_detail_string()));
} catch (const std::exception& e){
Expand Down
8 changes: 8 additions & 0 deletions plugins/http_client_plugin/http_client_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ void http_client_plugin::plugin_initialize(const variables_map& options) {
EOS_ASSERT( boost::algorithm::starts_with( pem_str, "-----BEGIN CERTIFICATE-----\n" ),
chain::invalid_http_client_root_cert,
"File does not appear to be a PEM encoded certificate" );
} catch ( const std::bad_alloc& ) {
throw;
} catch ( const boost::interprocess::bad_alloc& ) {
throw;
} catch ( const fc::exception& e ) {
elog( "Failed to read PEM ${f} : ${e}", ("f", root_pem)( "e", e.to_detail_string()));
} catch ( const std::exception& e ) {
Expand All @@ -42,6 +46,10 @@ void http_client_plugin::plugin_initialize(const variables_map& options) {

try {
my->add_cert( pem_str );
} catch ( const std::bad_alloc& ) {
throw;
} catch ( const boost::interprocess::bad_alloc& ) {
throw;
} catch ( const fc::exception& e ) {
elog( "Failed to read PEM : ${e} \n${pem}\n", ("pem", pem_str)( "e", e.to_detail_string()));
} catch ( const std::exception& e ) {
Expand Down
17 changes: 15 additions & 2 deletions plugins/net_plugin/net_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,10 @@ namespace eosio {

c->enqueue_sync_block();
c->do_queue_write();
} catch ( const std::bad_alloc& ) {
throw;
} catch ( const boost::interprocess::bad_alloc& ) {
throw;
} catch( const fc::exception& ex ) {
fc_elog( logger, "Exception in do_queue_write to ${p} ${s}", ("p", c->peer_name())( "s", ex.to_string() ) );
} catch( const std::exception& ex ) {
Expand Down Expand Up @@ -2475,8 +2479,17 @@ namespace eosio {
}
close_connection = true;
}
}
catch(const fc::exception &ex) {
}
catch ( const std::bad_alloc& )
{
throw;
}
catch ( const boost::interprocess::bad_alloc& )
{
throw;
}
catch(const fc::exception &ex)
{
fc_elog( logger, "Exception in handling read data ${s}", ("s",ex.to_string()) );
close_connection = true;
}
Expand Down
8 changes: 8 additions & 0 deletions plugins/producer_plugin/producer_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,10 @@ void producer_plugin::plugin_startup()
void producer_plugin::plugin_shutdown() {
try {
my->_timer.cancel();
} catch ( const std::bad_alloc& ) {
chain_plugin::handle_bad_alloc();
} catch ( const boost::interprocess::bad_alloc& ) {
chain_plugin::handle_bad_alloc();
} catch(const fc::exception& e) {
edump((e.to_detail_string()));
} catch(const std::exception& e) {
Expand Down Expand Up @@ -1472,6 +1476,10 @@ producer_plugin_impl::start_block_result producer_plugin_impl::start_block() {
bool drop_features_to_activate = false;
try {
chain.validate_protocol_features( _protocol_features_to_activate );
} catch ( const std::bad_alloc& ) {
chain_plugin::handle_bad_alloc();
} catch ( const boost::interprocess::bad_alloc& ) {
chain_plugin::handle_bad_alloc();
} catch( const fc::exception& e ) {
wlog( "protocol features to activate are no longer all valid: ${details}",
("details",e.to_detail_string()) );
Expand Down
4 changes: 4 additions & 0 deletions plugins/trace_api_plugin/utils/compress_cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ namespace {
} catch (const bpo::error& e) {
std::cerr << "Error: " << e.what() << "\n\n";
print_help_text(std::cerr, vis_desc);
} catch ( const std::bad_alloc& ) {
throw;
} catch ( const boost::interprocess::bad_alloc& ) {
throw;
} catch (const fc::exception& e) {
std::cerr << "Error: " << e.to_detail_string() << "\n";
} catch (const std::exception& e) {
Expand Down
8 changes: 8 additions & 0 deletions plugins/txn_test_gen_plugin/txn_test_gen_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ struct txn_test_gen_plugin_impl {
trx.sign(txn_test_receiver_C_priv_key, chainid);
trxs.emplace_back(std::move(trx));
}
} catch ( const std::bad_alloc& ) {
throw;
} catch ( const boost::interprocess::bad_alloc& ) {
throw;
} catch (const fc::exception& e) {
next(e.dynamic_copy_exception());
return;
Expand Down Expand Up @@ -382,6 +386,10 @@ struct txn_test_gen_plugin_impl {
trxs.emplace_back(std::move(trx));
}
}
} catch ( const std::bad_alloc& ) {
throw;
} catch ( const boost::interprocess::bad_alloc& ) {
throw;
} catch ( const fc::exception& e ) {
next(e.dynamic_copy_exception());
} catch (const std::exception& e) {
Expand Down
6 changes: 5 additions & 1 deletion programs/cleos/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4153,8 +4153,12 @@ int main( int argc, char** argv ) {
elog("connect error: ${e}", ("e", e.to_detail_string()));
}
return 1;
} catch ( const std::bad_alloc& ) {
elog("bad alloc");
} catch( const boost::interprocess::bad_alloc& ) {
elog("bad alloc");
} catch (const fc::exception& e) {
return handle_error(e);
return handle_error(e);
} catch (const std::exception& e) {
return handle_error(fc::std_exception_wrapper::from_current_exception(e));
}
Expand Down
10 changes: 9 additions & 1 deletion programs/nodeos-sectl/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,15 @@ int main(int argc, char** argv) {
try {
bpo::store(bpo::parse_command_line(argc, argv, cli), varmap);
bpo::notify(varmap);
}
}
catch ( const std::bad_alloc& ) {
elog("bad alloc");
return BAD_ALLOC;
}
catch ( const boost::interprocess::bad_alloc& ) {
elog("bad alloc");
return BAD_ALLOC;
}
catch(const fc::exception& e) {
elog("${e}", ("e", e.to_detail_string()));
return 1;
Expand Down

0 comments on commit d99f933

Please sign in to comment.