From c57a65b246021d37653e944caa30be628e6878f1 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Thu, 27 Sep 2018 10:54:35 +0000 Subject: [PATCH 01/20] blockchain_blackball: fix shift range for 32 bit archs Coverity 188406 --- src/blockchain_utilities/blockchain_blackball.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/blockchain_utilities/blockchain_blackball.cpp b/src/blockchain_utilities/blockchain_blackball.cpp index 1c6e54d10..81c9bf705 100644 --- a/src/blockchain_utilities/blockchain_blackball.cpp +++ b/src/blockchain_utilities/blockchain_blackball.cpp @@ -675,7 +675,7 @@ static uint64_t get_ring_subset_instances(MDB_txn *txn, uint64_t amount, const s uint64_t extra = 0; std::vector subset; subset.reserve(ring.size()); - for (uint64_t mask = 1; mask < (1u << ring.size()) - 1; ++mask) + for (uint64_t mask = 1; mask < (((uint64_t)1) << ring.size()) - 1; ++mask) { subset.resize(0); for (size_t i = 0; i < ring.size(); ++i) From 02563bf4b9bb6addd19d600835ae0a2699cc5049 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Thu, 27 Sep 2018 10:56:54 +0000 Subject: [PATCH 02/20] simplewallet: top level exception catcher to print nicer messages Coverity 188408 --- src/simplewallet/simplewallet.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 302d2a999..7037d4972 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -8072,6 +8072,8 @@ void simple_wallet::commit_or_save(std::vector& ptx_ //---------------------------------------------------------------------------------------------------- int main(int argc, char* argv[]) { + TRY_ENTRY(); + #ifdef WIN32 // Activate UTF-8 support for Boost filesystem classes on Windows std::locale::global(boost::locale::generator().generate("")); @@ -8166,5 +8168,5 @@ int main(int argc, char* argv[]) w.deinit(); } return 0; - //CATCH_ENTRY_L0("main", 1); + CATCH_ENTRY_L0("main", 1); } From d8b1ec8b8bafc67763d660360be3c75a06f99f00 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Thu, 27 Sep 2018 11:28:34 +0000 Subject: [PATCH 03/20] unit_tests: use std::shared_ptr to shut coverity up about leaks Coverity 188436, 188433, 188428, 188415, 188416, 188410, 188400, 188298, 188299, 188321, 188342, 188343, 188355, 188357, 188361, 188366, 188374 --- tests/unit_tests/mlocker.cpp | 68 ++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/tests/unit_tests/mlocker.cpp b/tests/unit_tests/mlocker.cpp index 480940374..93434baf0 100644 --- a/tests/unit_tests/mlocker.cpp +++ b/tests/unit_tests/mlocker.cpp @@ -46,14 +46,14 @@ TEST(mlocker, distinct_1) const size_t base_pages = epee::mlocker::get_num_locked_pages(); const size_t base_objects = epee::mlocker::get_num_locked_objects(); std::unique_ptr data{new char[8 * page_size]}; - epee::mlocker *m0 = new epee::mlocker(BASE(data), 1); - epee::mlocker *m1 = new epee::mlocker(BASE(data) + 2 * page_size, 1); - epee::mlocker *m2 = new epee::mlocker(BASE(data) + 3 * page_size, 1); + std::shared_ptr m0{new epee::mlocker(BASE(data), 1)}; + std::shared_ptr m1{new epee::mlocker(BASE(data) + 2 * page_size, 1)}; + std::shared_ptr m2{new epee::mlocker(BASE(data) + 3 * page_size, 1)}; ASSERT_EQ(epee::mlocker::get_num_locked_pages(), base_pages + 3); ASSERT_EQ(epee::mlocker::get_num_locked_objects(), base_objects + 3); - delete m0; - delete m1; - delete m2; + m0 = NULL; + m1 = NULL; + m2 = NULL; ASSERT_EQ(epee::mlocker::get_num_locked_pages(), base_pages + 0); ASSERT_EQ(epee::mlocker::get_num_locked_objects(), base_objects + 0); } @@ -65,14 +65,14 @@ TEST(mlocker, distinct_full_page) const size_t base_pages = epee::mlocker::get_num_locked_pages(); const size_t base_objects = epee::mlocker::get_num_locked_objects(); std::unique_ptr data{new char[8 * page_size]}; - epee::mlocker *m0 = new epee::mlocker(BASE(data), page_size); - epee::mlocker *m1 = new epee::mlocker(BASE(data) + 2 * page_size, page_size); - epee::mlocker *m2 = new epee::mlocker(BASE(data) + 3 * page_size, page_size); + std::shared_ptr m0{new epee::mlocker(BASE(data), page_size)}; + std::shared_ptr m1{new epee::mlocker(BASE(data) + 2 * page_size, page_size)}; + std::shared_ptr m2{new epee::mlocker(BASE(data) + 3 * page_size, page_size)}; ASSERT_EQ(epee::mlocker::get_num_locked_pages(), base_pages + 3); ASSERT_EQ(epee::mlocker::get_num_locked_objects(), base_objects + 3); - delete m0; - delete m1; - delete m2; + m0 = NULL; + m1 = NULL; + m2 = NULL; ASSERT_EQ(epee::mlocker::get_num_locked_pages(), base_pages + 0); ASSERT_EQ(epee::mlocker::get_num_locked_objects(), base_objects + 0); } @@ -84,16 +84,16 @@ TEST(mlocker, identical) const size_t base_pages = epee::mlocker::get_num_locked_pages(); const size_t base_objects = epee::mlocker::get_num_locked_objects(); std::unique_ptr data{new char[8 * page_size]}; - epee::mlocker *m0 = new epee::mlocker(BASE(data) + page_size, 32); - epee::mlocker *m1 = new epee::mlocker(BASE(data) + page_size, 32); - epee::mlocker *m2 = new epee::mlocker(BASE(data) + page_size, 32); + std::shared_ptr m0{new epee::mlocker(BASE(data) + page_size, 32)}; + std::shared_ptr m1{new epee::mlocker(BASE(data) + page_size, 32)}; + std::shared_ptr m2{new epee::mlocker(BASE(data) + page_size, 32)}; ASSERT_EQ(epee::mlocker::get_num_locked_pages(), base_pages + 1); ASSERT_EQ(epee::mlocker::get_num_locked_objects(), base_objects + 3); - delete m1; + m1 = NULL; ASSERT_EQ(epee::mlocker::get_num_locked_pages(), base_pages + 1); ASSERT_EQ(epee::mlocker::get_num_locked_objects(), base_objects + 2); - delete m0; - delete m2; + m0 = NULL; + m2 = NULL; ASSERT_EQ(epee::mlocker::get_num_locked_pages(), base_pages + 0); ASSERT_EQ(epee::mlocker::get_num_locked_objects(), base_objects + 0); } @@ -105,16 +105,16 @@ TEST(mlocker, overlapping_small) const size_t base_pages = epee::mlocker::get_num_locked_pages(); const size_t base_objects = epee::mlocker::get_num_locked_objects(); std::unique_ptr data{new char[8 * page_size]}; - epee::mlocker *m0 = new epee::mlocker(BASE(data), 32); - epee::mlocker *m1 = new epee::mlocker(BASE(data) + 16, 32); - epee::mlocker *m2 = new epee::mlocker(BASE(data) + 8, 32); + std::shared_ptr m0{new epee::mlocker(BASE(data), 32)}; + std::shared_ptr m1{new epee::mlocker(BASE(data) + 16, 32)}; + std::shared_ptr m2{new epee::mlocker(BASE(data) + 8, 32)}; ASSERT_EQ(epee::mlocker::get_num_locked_pages(), base_pages + 1); ASSERT_EQ(epee::mlocker::get_num_locked_objects(), base_objects + 3); - delete m1; + m1 = NULL; ASSERT_EQ(epee::mlocker::get_num_locked_pages(), base_pages + 1); ASSERT_EQ(epee::mlocker::get_num_locked_objects(), base_objects + 2); - delete m2; - delete m0; + m2 = NULL; + m0 = NULL; ASSERT_EQ(epee::mlocker::get_num_locked_pages(), base_pages + 0); ASSERT_EQ(epee::mlocker::get_num_locked_objects(), base_objects + 0); } @@ -126,16 +126,16 @@ TEST(mlocker, multi_page) const size_t base_pages = epee::mlocker::get_num_locked_pages(); const size_t base_objects = epee::mlocker::get_num_locked_objects(); std::unique_ptr data{new char[8 * page_size]}; - epee::mlocker *m0 = new epee::mlocker(BASE(data) + page_size, page_size * 3); + std::shared_ptr m0{new epee::mlocker(BASE(data) + page_size, page_size * 3)}; ASSERT_EQ(epee::mlocker::get_num_locked_pages(), base_pages + 3); ASSERT_EQ(epee::mlocker::get_num_locked_objects(), base_objects + 1); - epee::mlocker *m1 = new epee::mlocker(BASE(data) + page_size * 7, page_size); + std::shared_ptr m1{new epee::mlocker(BASE(data) + page_size * 7, page_size)}; ASSERT_EQ(epee::mlocker::get_num_locked_pages(), base_pages + 4); ASSERT_EQ(epee::mlocker::get_num_locked_objects(), base_objects + 2); - delete m0; + m0 = NULL; ASSERT_EQ(epee::mlocker::get_num_locked_pages(), base_pages + 1); ASSERT_EQ(epee::mlocker::get_num_locked_objects(), base_objects + 1); - delete m1; + m1 = NULL; ASSERT_EQ(epee::mlocker::get_num_locked_pages(), base_pages + 0); ASSERT_EQ(epee::mlocker::get_num_locked_objects(), base_objects + 0); } @@ -147,10 +147,10 @@ TEST(mlocker, cross_page) const size_t base_pages = epee::mlocker::get_num_locked_pages(); const size_t base_objects = epee::mlocker::get_num_locked_objects(); std::unique_ptr data{new char[2 * page_size]}; - epee::mlocker *m0 = new epee::mlocker(BASE(data) + page_size - 1, 2); + std::shared_ptr m0{new epee::mlocker(BASE(data) + page_size - 1, 2)}; ASSERT_EQ(epee::mlocker::get_num_locked_pages(), base_pages + 2); ASSERT_EQ(epee::mlocker::get_num_locked_objects(), base_objects + 1); - delete m0; + m0 = NULL; ASSERT_EQ(epee::mlocker::get_num_locked_pages(), base_pages + 0); ASSERT_EQ(epee::mlocker::get_num_locked_objects(), base_objects + 0); } @@ -163,16 +163,16 @@ TEST(mlocker, redundant) std::unique_ptr data{new char[2 * page_size]}; ASSERT_EQ(epee::mlocker::get_num_locked_pages(), base_pages + 0); ASSERT_EQ(epee::mlocker::get_num_locked_objects(), base_objects + 0); - epee::mlocker *m0 = new epee::mlocker(BASE(data), 32); + std::shared_ptr m0{new epee::mlocker(BASE(data), 32)}; ASSERT_EQ(epee::mlocker::get_num_locked_pages(), base_pages + 1); ASSERT_EQ(epee::mlocker::get_num_locked_objects(), base_objects + 1); - epee::mlocker *m1 = new epee::mlocker(BASE(data), 32); + std::shared_ptr m1{new epee::mlocker(BASE(data), 32)}; ASSERT_EQ(epee::mlocker::get_num_locked_pages(), base_pages + 1); ASSERT_EQ(epee::mlocker::get_num_locked_objects(), base_objects + 2); - delete m1; + m1 = NULL; ASSERT_EQ(epee::mlocker::get_num_locked_pages(), base_pages + 1); ASSERT_EQ(epee::mlocker::get_num_locked_objects(), base_objects + 1); - delete m0; + m0 = NULL; ASSERT_EQ(epee::mlocker::get_num_locked_pages(), base_pages + 0); ASSERT_EQ(epee::mlocker::get_num_locked_objects(), base_objects + 0); } From a085da32476148f86a0688c10cf97260c1a4bc23 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Thu, 27 Sep 2018 11:54:50 +0000 Subject: [PATCH 04/20] unit_tests: add check for page size > 0 before dividing Coverity 188426 --- tests/unit_tests/mlocker.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit_tests/mlocker.cpp b/tests/unit_tests/mlocker.cpp index 93434baf0..c97dc2c1d 100644 --- a/tests/unit_tests/mlocker.cpp +++ b/tests/unit_tests/mlocker.cpp @@ -158,6 +158,7 @@ TEST(mlocker, cross_page) TEST(mlocker, redundant) { const size_t page_size = epee::mlocker::get_page_size(); + ASSERT_TRUE(page_size > 0); const size_t base_pages = epee::mlocker::get_num_locked_pages(); const size_t base_objects = epee::mlocker::get_num_locked_objects(); std::unique_ptr data{new char[2 * page_size]}; From 7ece1550e185039914a65d93360769e5954ba407 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Thu, 27 Sep 2018 12:53:12 +0000 Subject: [PATCH 05/20] performance_test: fix bad last argument calling add_arg Coverity 182572 --- tests/performance_tests/main.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/performance_tests/main.cpp b/tests/performance_tests/main.cpp index 7c5135c65..87a1573c2 100644 --- a/tests/performance_tests/main.cpp +++ b/tests/performance_tests/main.cpp @@ -75,10 +75,10 @@ int main(int argc, char** argv) const command_line::arg_descriptor arg_verbose = { "verbose", "Verbose output", false }; const command_line::arg_descriptor arg_stats = { "stats", "Including statistics (min/median)", false }; const command_line::arg_descriptor arg_loop_multiplier = { "loop-multiplier", "Run for that many times more loops", 1 }; - command_line::add_arg(desc_options, arg_filter, ""); - command_line::add_arg(desc_options, arg_verbose, ""); - command_line::add_arg(desc_options, arg_stats, ""); - command_line::add_arg(desc_options, arg_loop_multiplier, ""); + command_line::add_arg(desc_options, arg_filter); + command_line::add_arg(desc_options, arg_verbose); + command_line::add_arg(desc_options, arg_stats); + command_line::add_arg(desc_options, arg_loop_multiplier); po::variables_map vm; bool r = command_line::handle_error_helper(desc_options, [&]() From 5fdcda50eeed473dc330b6dde332635998dcb097 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Thu, 27 Sep 2018 13:25:28 +0000 Subject: [PATCH 06/20] easylogging++: test for NULL before dereference --- external/easylogging++/easylogging++.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/external/easylogging++/easylogging++.cc b/external/easylogging++/easylogging++.cc index b438fa543..a4bdad4cf 100644 --- a/external/easylogging++/easylogging++.cc +++ b/external/easylogging++/easylogging++.cc @@ -1975,11 +1975,11 @@ void VRegistry::setCategories(const char* categories, bool clear) { m_cached_allowed_categories.clear(); m_categoriesString.clear(); } + if (!categories) + return; if (!m_categoriesString.empty()) m_categoriesString += ","; m_categoriesString += categories; - if (!categories) - return; bool isCat = true; bool isLevel = false; From 661439f4e057f06cd637bd5d467ef70f213755aa Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Thu, 27 Sep 2018 14:58:55 +0000 Subject: [PATCH 07/20] mlog: don't remove old logs if we failed to rename the current file Coverity 188348 --- contrib/epee/src/mlog.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/contrib/epee/src/mlog.cpp b/contrib/epee/src/mlog.cpp index cd9867ff5..61d853ef4 100644 --- a/contrib/epee/src/mlog.cpp +++ b/contrib/epee/src/mlog.cpp @@ -137,7 +137,12 @@ void mlog_configure(const std::string &filename_base, bool console, const std::s el::Loggers::addFlag(el::LoggingFlag::StrictLogFileSizeCheck); el::Helpers::installPreRollOutCallback([filename_base, max_log_files](const char *name, size_t){ std::string rname = generate_log_filename(filename_base.c_str()); - rename(name, rname.c_str()); + int ret = rename(name, rname.c_str()); + if (ret < 0) + { + // can't log a failure, but don't do the file removal below + return; + } if (max_log_files != 0) { std::vector found_files; From e67016ddb4d97400e4dfb7a8f2a37dc103d65cf4 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Thu, 27 Sep 2018 15:01:56 +0000 Subject: [PATCH 08/20] blockchain_blackball: catch failure to commit db transaction Coverity 188349 --- src/blockchain_utilities/blockchain_blackball.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/blockchain_utilities/blockchain_blackball.cpp b/src/blockchain_utilities/blockchain_blackball.cpp index 81c9bf705..5eb2acc79 100644 --- a/src/blockchain_utilities/blockchain_blackball.cpp +++ b/src/blockchain_utilities/blockchain_blackball.cpp @@ -401,7 +401,8 @@ static bool for_all_transactions(const std::string &filename, uint64_t &start_id } mdb_cursor_close(cur); - mdb_txn_commit(txn); + dbr = mdb_txn_commit(txn); + if (dbr) throw std::runtime_error("Failed to commit db transaction: " + std::string(mdb_strerror(dbr))); tx_active = false; mdb_dbi_close(env, dbi); mdb_env_close(env); @@ -471,7 +472,8 @@ static uint64_t find_first_diverging_transaction(const std::string &first_filena for (int i = 0; i < 2; ++i) { mdb_cursor_close(cur[i]); - mdb_txn_commit(txn[i]); + dbr = mdb_txn_commit(txn[i]); + if (dbr) throw std::runtime_error("Failed to query transaction: " + std::string(mdb_strerror(dbr))); tx_active[i] = false; mdb_dbi_close(env[i], dbi[i]); mdb_env_close(env[i]); From 53df2deb36079906ccf18133180a51d7a2017008 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Thu, 27 Sep 2018 15:07:52 +0000 Subject: [PATCH 09/20] db_lmdb: catch error in mdb_stat calls during migration Coverity 188305 --- src/blockchain_db/lmdb/db_lmdb.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp index b0f3ca5f0..10bc3a355 100644 --- a/src/blockchain_db/lmdb/db_lmdb.cpp +++ b/src/blockchain_db/lmdb/db_lmdb.cpp @@ -3579,7 +3579,9 @@ void BlockchainLMDB::migrate_0_1() throw0(DB_ERROR(lmdb_error("Failed to open a cursor for block_heights: ", result).c_str())); if (!i) { MDB_stat ms; - mdb_stat(txn, m_block_heights, &ms); + result = mdb_stat(txn, m_block_heights, &ms); + if (result) + throw0(DB_ERROR(lmdb_error("Failed to query block_heights table: ", result).c_str())); i = ms.ms_entries; } } @@ -3682,7 +3684,9 @@ void BlockchainLMDB::migrate_0_1() throw0(DB_ERROR(lmdb_error("Failed to open a cursor for block_timestamps: ", result).c_str())); if (!i) { MDB_stat ms; - mdb_stat(txn, m_block_info, &ms); + result = mdb_stat(txn, m_block_info, &ms); + if (result) + throw0(DB_ERROR(lmdb_error("Failed to query block_info table: ", result).c_str())); i = ms.ms_entries; } } @@ -3802,7 +3806,9 @@ void BlockchainLMDB::migrate_0_1() throw0(DB_ERROR(lmdb_error("Failed to open a cursor for spent_keys: ", result).c_str())); if (!i) { MDB_stat ms; - mdb_stat(txn, m_hf_versions, &ms); + result = mdb_stat(txn, m_hf_versions, &ms); + if (result) + throw0(DB_ERROR(lmdb_error("Failed to query hf_versions table: ", result).c_str())); i = ms.ms_entries; } } @@ -3957,7 +3963,9 @@ void BlockchainLMDB::migrate_0_1() throw0(DB_ERROR(lmdb_error("Failed to open a cursor for txs: ", result).c_str())); if (!i) { MDB_stat ms; - mdb_stat(txn, m_txs, &ms); + result = mdb_stat(txn, m_txs, &ms); + if (result) + throw0(DB_ERROR(lmdb_error("Failed to query txs table: ", result).c_str())); i = ms.ms_entries; if (i) { MDB_val_set(pk, "txblk"); From 6e8554221fbdc4bb4dd236bd6b02e8a96c452755 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Thu, 27 Sep 2018 15:12:02 +0000 Subject: [PATCH 10/20] gen_multisig: nice exit on unhandled exception Coverity 182569 --- src/gen_multisig/gen_multisig.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/gen_multisig/gen_multisig.cpp b/src/gen_multisig/gen_multisig.cpp index f11f442bc..69be70e1b 100644 --- a/src/gen_multisig/gen_multisig.cpp +++ b/src/gen_multisig/gen_multisig.cpp @@ -167,6 +167,8 @@ static bool generate_multisig(uint32_t threshold, uint32_t total, const std::str int main(int argc, char* argv[]) { + TRY_ENTRY(); + po::options_description desc_params(wallet_args::tr("Wallet options")); command_line::add_arg(desc_params, arg_filename_base); command_line::add_arg(desc_params, arg_scheme); @@ -254,5 +256,5 @@ int main(int argc, char* argv[]) return 1; return 0; - //CATCH_ENTRY_L0("main", 1); + CATCH_ENTRY_L0("main", 1); } From ea7f9543817993e22faf94478f07aac746729f73 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Thu, 27 Sep 2018 15:14:51 +0000 Subject: [PATCH 11/20] threadpool: do not propagate exceptions through the dtor This would call terminate. We ignore exceptions in pthread_join instead, as this is not a fatal problem here. Coverity 182568 --- src/common/threadpool.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/common/threadpool.cpp b/src/common/threadpool.cpp index 6b69e2a12..5ea04a353 100644 --- a/src/common/threadpool.cpp +++ b/src/common/threadpool.cpp @@ -57,7 +57,8 @@ threadpool::~threadpool() { has_work.notify_all(); } for (size_t i = 0; i Date: Thu, 27 Sep 2018 15:17:49 +0000 Subject: [PATCH 12/20] unit_tests: catch unhandled exceptions Coverity 182560 --- tests/unit_tests/main.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/unit_tests/main.cpp b/tests/unit_tests/main.cpp index 13b62cbb4..f7251a09e 100644 --- a/tests/unit_tests/main.cpp +++ b/tests/unit_tests/main.cpp @@ -53,6 +53,8 @@ namespace cryptonote { template class t_cryptonote_protocol_handler Date: Thu, 27 Sep 2018 15:37:44 +0000 Subject: [PATCH 13/20] wallet_rpc_server: exit cleanly on unhandled exceptions Coverity 161868 --- src/wallet/wallet_rpc_server.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index e6eb64d12..b30a80359 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -3457,6 +3457,8 @@ public: std::string const t_executor::NAME = "Wallet RPC Daemon"; int main(int argc, char** argv) { + TRY_ENTRY(); + namespace po = boost::program_options; const auto arg_wallet_file = wallet_args::arg_wallet_file(); @@ -3500,4 +3502,5 @@ int main(int argc, char** argv) { } return daemonizer::daemonize(argc, const_cast(argv), t_executor{}, *vm) ? 0 : 1; + CATCH_ENTRY_L0("main", 1); } From 0749a8bd3cd5ff0814a41d9a2a8b5c72954c6ce6 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Thu, 27 Sep 2018 15:39:54 +0000 Subject: [PATCH 14/20] db_lmdb: do not propagate exceptions in dtor Not much we can do here Coverity 161875 --- src/blockchain_db/lmdb/db_lmdb.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp index 10bc3a355..bf88884fd 100644 --- a/src/blockchain_db/lmdb/db_lmdb.cpp +++ b/src/blockchain_db/lmdb/db_lmdb.cpp @@ -1145,7 +1145,10 @@ BlockchainLMDB::~BlockchainLMDB() // batch transaction shouldn't be active at this point. If it is, consider it aborted. if (m_batch_active) - batch_abort(); + { + try { batch_abort(); } + catch (...) { /* ignore */ } + } if (m_open) close(); } From 2e2139ffb79c225a49f3ce5b002dc200d7ca5b02 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Thu, 27 Sep 2018 17:40:56 +0000 Subject: [PATCH 15/20] epee: do not propagate exception through dtor Coverity 161867 --- contrib/epee/include/console_handler.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contrib/epee/include/console_handler.h b/contrib/epee/include/console_handler.h index 0e22a971c..2ccf5b095 100644 --- a/contrib/epee/include/console_handler.h +++ b/contrib/epee/include/console_handler.h @@ -63,7 +63,8 @@ namespace epee ~async_stdin_reader() { - stop(); + try { stop(); } + catch (...) { /* ignore */ } } #ifdef HAVE_READLINE From fb6a363050372358646331712173c9fa620dd29c Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Thu, 27 Sep 2018 17:42:39 +0000 Subject: [PATCH 16/20] miner: do not propagate exceptions through dtor Coverity 161862 --- src/cryptonote_basic/miner.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cryptonote_basic/miner.cpp b/src/cryptonote_basic/miner.cpp index dfe456ef4..28ceee0cd 100644 --- a/src/cryptonote_basic/miner.cpp +++ b/src/cryptonote_basic/miner.cpp @@ -121,7 +121,8 @@ namespace cryptonote //----------------------------------------------------------------------------------------------------- miner::~miner() { - stop(); + try { stop(); } + catch (...) { /* ignore */ } } //----------------------------------------------------------------------------------------------------- bool miner::set_block_template(const block& bl, const difficulty_type& di, uint64_t height) From 1eebb82bccad539d6c4e4579632137065086b890 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Thu, 27 Sep 2018 17:43:49 +0000 Subject: [PATCH 17/20] net_helper: do not propagate exceptions through dtor Coverity 161864 --- contrib/epee/include/net/net_helper.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contrib/epee/include/net/net_helper.h b/contrib/epee/include/net/net_helper.h index 2c2efcd82..94744ac21 100644 --- a/contrib/epee/include/net/net_helper.h +++ b/contrib/epee/include/net/net_helper.h @@ -106,7 +106,8 @@ namespace net_utils ~blocked_mode_client() { //profile_tools::local_coast lc("~blocked_mode_client()", 3); - shutdown(); + try { shutdown(); } + catch(...) { /* ignore */ } } inline From a093092ef7fad731853fb8ea7b39c9f35ff4315c Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Thu, 27 Sep 2018 17:46:39 +0000 Subject: [PATCH 18/20] levin_protocol_handler_async: do not propagate exception through dtor Coverity 161856 --- contrib/epee/include/net/levin_protocol_handler_async.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/contrib/epee/include/net/levin_protocol_handler_async.h b/contrib/epee/include/net/levin_protocol_handler_async.h index 0b1fe05fa..e9853ee26 100644 --- a/contrib/epee/include/net/levin_protocol_handler_async.h +++ b/contrib/epee/include/net/levin_protocol_handler_async.h @@ -275,6 +275,9 @@ public: } virtual ~async_protocol_handler() { + try + { + m_deletion_initiated = true; if(m_connection_initialized) { @@ -288,6 +291,9 @@ public: CHECK_AND_ASSERT_MES_NO_RET(0 == boost::interprocess::ipcdetail::atomic_read32(&m_wait_count), "Failed to wait for operation completion. m_wait_count = " << m_wait_count); MTRACE(m_connection_context << "~async_protocol_handler()"); + + } + catch (...) { /* ignore */ } } bool start_outer_call() From 3ebd05d4e526d884b4aa5075328d72625853a556 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Thu, 27 Sep 2018 18:17:32 +0000 Subject: [PATCH 19/20] miner: restore stream flags after changing them Coverity 136462 --- src/cryptonote_basic/miner.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cryptonote_basic/miner.cpp b/src/cryptonote_basic/miner.cpp index 28ceee0cd..2bd43de94 100644 --- a/src/cryptonote_basic/miner.cpp +++ b/src/cryptonote_basic/miner.cpp @@ -199,8 +199,9 @@ namespace cryptonote { uint64_t total_hr = std::accumulate(m_last_hash_rates.begin(), m_last_hash_rates.end(), 0); float hr = static_cast(total_hr)/static_cast(m_last_hash_rates.size()); + const auto flags = std::cout.flags(); const auto precision = std::cout.precision(); - std::cout << "hashrate: " << std::setprecision(4) << std::fixed << hr << precision << ENDL; + std::cout << "hashrate: " << std::setprecision(4) << std::fixed << hr << flags << precision << ENDL; } } m_last_hr_merge_time = misc_utils::get_tick_count(); From bcf3f6afdd92345da874c4b1241d71b03cabccf3 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Thu, 27 Sep 2018 18:23:24 +0000 Subject: [PATCH 20/20] fuzz_tests: catch unhandled exceptions Coverity 175293, 175312, 175266 --- tests/fuzz/fuzzer.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/fuzz/fuzzer.cpp b/tests/fuzz/fuzzer.cpp index 032ff049a..ab14e2b79 100644 --- a/tests/fuzz/fuzzer.cpp +++ b/tests/fuzz/fuzzer.cpp @@ -46,6 +46,8 @@ static int __AFL_LOOP(int) int run_fuzzer(int argc, const char **argv, Fuzzer &fuzzer) { + TRY_ENTRY(); + if (argc < 2) { std::cout << "usage: " << argv[0] << " " << "" << std::endl; @@ -69,4 +71,6 @@ int run_fuzzer(int argc, const char **argv, Fuzzer &fuzzer) } return 0; + + CATCH_ENTRY_L0("run_fuzzer", 1); }