From 1aabd14c21221702b7efd84dfe43d17f6486db83 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Fri, 2 Feb 2018 15:08:22 +0000 Subject: [PATCH 01/14] db_lmdb: check hard fork info drop succeeded Coverity 136364 --- src/blockchain_db/lmdb/db_lmdb.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp index 6b81a4c90..604aae61e 100644 --- a/src/blockchain_db/lmdb/db_lmdb.cpp +++ b/src/blockchain_db/lmdb/db_lmdb.cpp @@ -3140,8 +3140,12 @@ void BlockchainLMDB::drop_hard_fork_info() TXN_PREFIX(0); - mdb_drop(*txn_ptr, m_hf_starting_heights, 1); - mdb_drop(*txn_ptr, m_hf_versions, 1); + auto result = mdb_drop(*txn_ptr, m_hf_starting_heights, 1); + if (result) + throw1(DB_ERROR(lmdb_error("Error dropping hard fork starting heights db: ", result).c_str())); + result = mdb_drop(*txn_ptr, m_hf_versions, 1); + if (result) + throw1(DB_ERROR(lmdb_error("Error dropping hard fork versions db: ", result).c_str())); TXN_POSTFIX_SUCCESS(); } From bece67f9e82b839b03f40634614f73a61034a658 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Fri, 2 Feb 2018 15:12:22 +0000 Subject: [PATCH 02/14] miner: restore std::cout precision after modification 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 6c4ecf58c..b322383a9 100644 --- a/src/cryptonote_basic/miner.cpp +++ b/src/cryptonote_basic/miner.cpp @@ -198,7 +198,8 @@ 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()); - std::cout << "hashrate: " << std::setprecision(4) << std::fixed << hr << ENDL; + const auto precision = std::cout.precision(); + std::cout << "hashrate: " << std::setprecision(4) << std::fixed << hr << precision << ENDL; } } m_last_hr_merge_time = misc_utils::get_tick_count(); From ad11db9144f766d86d4aa4904eecd446fb670597 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Fri, 2 Feb 2018 15:21:39 +0000 Subject: [PATCH 03/14] blockchain_db: initialize m_open in base class ctor It's cleaner this way, since it's a base class field Coverity 136568 --- src/blockchain_db/berkeleydb/db_bdb.cpp | 2 +- src/blockchain_db/blockchain_db.h | 5 +++++ src/blockchain_db/lmdb/db_lmdb.cpp | 3 +-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/blockchain_db/berkeleydb/db_bdb.cpp b/src/blockchain_db/berkeleydb/db_bdb.cpp index f540ce133..3a66ecb93 100644 --- a/src/blockchain_db/berkeleydb/db_bdb.cpp +++ b/src/blockchain_db/berkeleydb/db_bdb.cpp @@ -770,13 +770,13 @@ BlockchainBDB::~BlockchainBDB() } BlockchainBDB::BlockchainBDB(bool batch_transactions) : + BlockchainDB(), m_buffer(DB_BUFFER_COUNT, DB_BUFFER_LENGTH) { LOG_PRINT_L3("BlockchainBDB::" << __func__); // initialize folder to something "safe" just in case // someone accidentally misuses this class... m_folder = "thishsouldnotexistbecauseitisgibberish"; - m_open = false; m_run_checkpoint = 0; m_batch_transactions = batch_transactions; m_write_txn = nullptr; diff --git a/src/blockchain_db/blockchain_db.h b/src/blockchain_db/blockchain_db.h index 227169614..cce288793 100644 --- a/src/blockchain_db/blockchain_db.h +++ b/src/blockchain_db/blockchain_db.h @@ -537,6 +537,11 @@ protected: public: + /** + * @brief An empty constructor. + */ + BlockchainDB(): m_open(false) { } + /** * @brief An empty destructor. */ diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp index 604aae61e..149da53b6 100644 --- a/src/blockchain_db/lmdb/db_lmdb.cpp +++ b/src/blockchain_db/lmdb/db_lmdb.cpp @@ -1074,13 +1074,12 @@ BlockchainLMDB::~BlockchainLMDB() close(); } -BlockchainLMDB::BlockchainLMDB(bool batch_transactions) +BlockchainLMDB::BlockchainLMDB(bool batch_transactions): BlockchainDB() { LOG_PRINT_L3("BlockchainLMDB::" << __func__); // initialize folder to something "safe" just in case // someone accidentally misuses this class... m_folder = "thishsouldnotexistbecauseitisgibberish"; - m_open = false; m_batch_transactions = batch_transactions; m_write_txn = nullptr; From 03887f1140331326e3e6ca0a24161dd7ab74af1e Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Fri, 2 Feb 2018 15:48:06 +0000 Subject: [PATCH 04/14] keccak: fix sanity check bounds test Nothing calls this with those inputs --- src/crypto/keccak.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/crypto/keccak.c b/src/crypto/keccak.c index fc6d487c2..7386d37a3 100644 --- a/src/crypto/keccak.c +++ b/src/crypto/keccak.c @@ -99,7 +99,7 @@ void keccak(const uint8_t *in, size_t inlen, uint8_t *md, int mdlen) } // last block and padding - if (inlen >= sizeof(temp) || inlen > rsiz || rsiz - inlen + inlen + 1 >= sizeof(temp) || rsiz == 0 || rsiz - 1 >= sizeof(temp) || rsizw * 8 > sizeof(temp)) + if (inlen + 1 >= sizeof(temp) || inlen > rsiz || rsiz - inlen + inlen + 1 >= sizeof(temp) || rsiz == 0 || rsiz - 1 >= sizeof(temp) || rsizw * 8 > sizeof(temp)) { fprintf(stderr, "Bad keccak use"); abort(); From fa6b45665d6e7cab39c9c2f65f0f802f79003b95 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Fri, 2 Feb 2018 15:56:44 +0000 Subject: [PATCH 05/14] fuzz_tests: fix an uninitialized var in setup and comment it out, it's only used to generate a starting test case Coverity 182506 --- tests/fuzz/levin.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/fuzz/levin.cpp b/tests/fuzz/levin.cpp index 2c3971470..6a164dda9 100644 --- a/tests/fuzz/levin.cpp +++ b/tests/fuzz/levin.cpp @@ -299,7 +299,7 @@ int LevinFuzzer::run(const std::string &filename) { std::string s; -// +#if 0 epee::levin::bucket_head2 req_head; req_head.m_signature = LEVIN_SIGNATURE; req_head.m_cb = 0; @@ -307,10 +307,11 @@ int LevinFuzzer::run(const std::string &filename) req_head.m_command = 2000; req_head.m_flags = LEVIN_PACKET_REQUEST; req_head.m_protocol_version = LEVIN_PROTOCOL_VER_1; + req_head.m_return_code = 0; FILE *f=fopen("/tmp/out.levin", "w"); fwrite(&req_head,sizeof(req_head),1, f); fclose(f); -// +#endif if (!epee::file_io_utils::load_file_to_string(filename, s)) { std::cout << "Error: failed to load file " << filename << std::endl; From c6ea3df0aec99fdbd99e3b547268161c73ac2255 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Fri, 2 Feb 2018 15:59:54 +0000 Subject: [PATCH 06/14] performance_tests: remove add_arg call stray extra param Coverity 182572 --- tests/performance_tests/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/performance_tests/main.cpp b/tests/performance_tests/main.cpp index d1b79d026..faf87f9de 100644 --- a/tests/performance_tests/main.cpp +++ b/tests/performance_tests/main.cpp @@ -84,7 +84,7 @@ int main(int argc, char** argv) po::options_description desc_options("Command line options"); const command_line::arg_descriptor arg_filter = { "filter", "Regular expression filter for which tests to run" }; - command_line::add_arg(desc_options, arg_filter, ""); + command_line::add_arg(desc_options, arg_filter); po::variables_map vm; bool r = command_line::handle_error_helper(desc_options, [&]() From f3f7da624de546c8f4e6b236d364377b19c49d78 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Fri, 2 Feb 2018 16:05:06 +0000 Subject: [PATCH 07/14] perf_timer: rewrite to make it clear there is no division by zero It could have happened if epee::misc_utils::get_ns_count is buggy, at a push Coverity 182561 --- src/common/perf_timer.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/common/perf_timer.cpp b/src/common/perf_timer.cpp index 41e23130d..16abdfd99 100644 --- a/src/common/perf_timer.cpp +++ b/src/common/perf_timer.cpp @@ -49,16 +49,15 @@ namespace #ifdef __x86_64__ uint64_t get_ticks_per_ns() { - uint64_t t0 = epee::misc_utils::get_ns_count(); + uint64_t t0 = epee::misc_utils::get_ns_count(), t1; uint64_t r0 = get_tick_count(); while (1) { - uint64_t t = epee::misc_utils::get_ns_count(); - if (t - t0 > 1*1000000000) break; // work one second + t1 = epee::misc_utils::get_ns_count(); + if (t1 - t0 > 1*1000000000) break; // work one second } - uint64_t t1 = epee::misc_utils::get_ns_count(); uint64_t r1 = get_tick_count(); uint64_t tpns256 = 256 * (r1 - r0) / (t1 - t0); return tpns256 ? tpns256 : 1; From 24803ed91f7e062ea66663d06daae2d30132f2cd Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Fri, 2 Feb 2018 16:10:34 +0000 Subject: [PATCH 08/14] blockchain_export: fix buffer overflow in exporter Coverity 182550 --- src/blockchain_utilities/blocksdat_file.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/blockchain_utilities/blocksdat_file.cpp b/src/blockchain_utilities/blocksdat_file.cpp index 2bad86dfd..45ef33acb 100644 --- a/src/blockchain_utilities/blocksdat_file.cpp +++ b/src/blockchain_utilities/blocksdat_file.cpp @@ -106,7 +106,7 @@ void BlocksdatFile::write_block(const crypto::hash& block_hash) { crypto::hash hash; crypto::cn_fast_hash(m_hashes.data(), HASH_OF_HASHES_STEP * sizeof(crypto::hash), hash); - memmove(m_hashes.data(), m_hashes.data() + HASH_OF_HASHES_STEP * sizeof(crypto::hash), (m_hashes.size() - HASH_OF_HASHES_STEP) * sizeof(crypto::hash)); + memmove(m_hashes.data(), m_hashes.data() + HASH_OF_HASHES_STEP, (m_hashes.size() - HASH_OF_HASHES_STEP) * sizeof(crypto::hash)); m_hashes.resize(m_hashes.size() - HASH_OF_HASHES_STEP); const std::string data(hash.data, sizeof(hash)); *m_raw_data_file << data; From 9b98a6ac8f750f5d786fe9a3a561373ca64e5049 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Fri, 2 Feb 2018 16:16:43 +0000 Subject: [PATCH 09/14] threadpool: catch exceptions in dtor, to avoid terminate If an exception is thrown, it is ignored. While this may hide a bug, this should only be system exceptions in boost, which is pretty unlikely. Morever, wait should be called manually before the dtor anyway. Add an error message if the dtor has to wait in case some such cases creep in so they get fixed. Coverity 182538 --- src/common/threadpool.cpp | 18 ++++++++++++++++++ src/common/threadpool.h | 3 ++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/common/threadpool.cpp b/src/common/threadpool.cpp index 7fd16ceaf..51e071577 100644 --- a/src/common/threadpool.cpp +++ b/src/common/threadpool.cpp @@ -25,6 +25,7 @@ // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#include "misc_log_ex.h" #include "common/threadpool.h" #include @@ -81,6 +82,23 @@ int threadpool::get_max_concurrency() { return max; } +threadpool::waiter::~waiter() +{ + { + boost::unique_lock lock(mt); + if (num) + MERROR("wait should have been called before waiter dtor - waiting now"); + } + try + { + wait(); + } + catch (const std::exception &e) + { + /* ignored */ + } +} + void threadpool::waiter::wait() { boost::unique_lock lock(mt); while(num) cv.wait(lock); diff --git a/src/common/threadpool.h b/src/common/threadpool.h index a0e53b011..34152541c 100644 --- a/src/common/threadpool.h +++ b/src/common/threadpool.h @@ -34,6 +34,7 @@ #include #include #include +#include namespace tools { @@ -57,7 +58,7 @@ public: void dec(); void wait(); //! Wait for a set of tasks to finish. waiter() : num(0){} - ~waiter() { wait(); } + ~waiter(); }; // Submit a task to the pool. The waiter pointer may be From 8cea8d0cef647b429af87036718347b629c5d4dc Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Fri, 2 Feb 2018 16:41:16 +0000 Subject: [PATCH 10/14] simplewallet: double check a new multisig wallet is multisig Coverity 182493 --- src/simplewallet/simplewallet.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index a6cef1bb9..b38ce7d86 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -816,7 +816,11 @@ bool simple_wallet::make_multisig(const std::vector &args) } uint32_t total; - m_wallet->multisig(NULL, &threshold, &total); + if (!m_wallet->multisig(NULL, &threshold, &total)) + { + fail_msg_writer() << tr("Error creating multisig: new wallet is not multisig"); + return true; + } success_msg_writer() << std::to_string(threshold) << "/" << total << tr(" multisig address: ") << m_wallet->get_account().get_public_address_str(m_wallet->testnet()); From 9af6b2d1b820d52340f9b89222cc8b07e5b29bb7 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Fri, 2 Feb 2018 16:44:28 +0000 Subject: [PATCH 11/14] ringct: fix infinite loop in unused h2b function Coverity 146775 --- src/ringct/rctTypes.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ringct/rctTypes.cpp b/src/ringct/rctTypes.cpp index 1526dcf7c..5650b3ba1 100644 --- a/src/ringct/rctTypes.cpp +++ b/src/ringct/rctTypes.cpp @@ -178,6 +178,7 @@ namespace rct { } while (i < 8 * (j + 1)) { amountb2[i] = 0; + i++; } } } From 61defd89e3f88f30d6a9fd9ba546c3317b61377e Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Fri, 2 Feb 2018 16:50:35 +0000 Subject: [PATCH 12/14] blockchain: sanity check number of precomputed hash of hash blocks Coverity 142951 --- src/cryptonote_core/blockchain.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index 178479f3c..6203f313c 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -4343,8 +4343,13 @@ void Blockchain::load_compiled_in_block_hashes() { const unsigned char *p = get_blocks_dat_start(m_testnet); const uint32_t nblocks = *p | ((*(p+1))<<8) | ((*(p+2))<<16) | ((*(p+3))<<24); + if (nblocks > (std::numeric_limits::max() - 4) / sizeof(hash)) + { + MERROR("Block hash data is too large"); + return; + } const size_t size_needed = 4 + nblocks * sizeof(crypto::hash); - if(nblocks > 0 && nblocks * HASH_OF_HASHES_STEP > m_db->height() && get_blocks_dat_size(m_testnet) >= size_needed) + if(nblocks > 0 && nblocks > (m_db->height() + HASH_OF_HASHES_STEP - 1) / HASH_OF_HASHES_STEP && get_blocks_dat_size(m_testnet) >= size_needed) { p += sizeof(uint32_t); m_blocks_hash_of_hashes.reserve(nblocks); From 2e3e90acbe62272901046f754b62ee7ec0d516d9 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Fri, 2 Feb 2018 18:45:12 +0000 Subject: [PATCH 13/14] pass large parameters by const ref, not value Coverity 136394 136397 136409 136526 136529 136533 175302 --- contrib/epee/include/net/abstract_tcp_server2.h | 2 +- .../epee/include/net/abstract_tcp_server2.inl | 2 +- .../include/net/levin_protocol_handler_async.h | 16 ++++++++-------- .../include/storages/levin_abstract_invoke2.h | 2 +- src/p2p/net_node.h | 2 +- src/p2p/net_node.inl | 2 +- tests/core_tests/block_validation.cpp | 2 +- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/contrib/epee/include/net/abstract_tcp_server2.h b/contrib/epee/include/net/abstract_tcp_server2.h index c0401c8b0..ccde928ba 100644 --- a/contrib/epee/include/net/abstract_tcp_server2.h +++ b/contrib/epee/include/net/abstract_tcp_server2.h @@ -207,7 +207,7 @@ namespace net_utils bool connect(const std::string& adr, const std::string& port, uint32_t conn_timeot, t_connection_context& cn, const std::string& bind_ip = "0.0.0.0"); template - bool connect_async(const std::string& adr, const std::string& port, uint32_t conn_timeot, t_callback cb, const std::string& bind_ip = "0.0.0.0"); + bool connect_async(const std::string& adr, const std::string& port, uint32_t conn_timeot, const t_callback &cb, const std::string& bind_ip = "0.0.0.0"); typename t_protocol_handler::config_type& get_config_object(){return m_config;} diff --git a/contrib/epee/include/net/abstract_tcp_server2.inl b/contrib/epee/include/net/abstract_tcp_server2.inl index 870f6c2b2..e5c0804f8 100644 --- a/contrib/epee/include/net/abstract_tcp_server2.inl +++ b/contrib/epee/include/net/abstract_tcp_server2.inl @@ -1055,7 +1055,7 @@ POP_WARNINGS } //--------------------------------------------------------------------------------- template template - bool boosted_tcp_server::connect_async(const std::string& adr, const std::string& port, uint32_t conn_timeout, t_callback cb, const std::string& bind_ip) + bool boosted_tcp_server::connect_async(const std::string& adr, const std::string& port, uint32_t conn_timeout, const t_callback &cb, const std::string& bind_ip) { TRY_ENTRY(); connection_ptr new_connection_l(new connection(io_service_, m_config, m_sock_count, m_sock_number, m_pfilter, m_connection_type) ); diff --git a/contrib/epee/include/net/levin_protocol_handler_async.h b/contrib/epee/include/net/levin_protocol_handler_async.h index ee64da5d8..9181076d7 100644 --- a/contrib/epee/include/net/levin_protocol_handler_async.h +++ b/contrib/epee/include/net/levin_protocol_handler_async.h @@ -84,16 +84,16 @@ public: int invoke(int command, const std::string& in_buff, std::string& buff_out, boost::uuids::uuid connection_id); template - int invoke_async(int command, const std::string& in_buff, boost::uuids::uuid connection_id, callback_t cb, size_t timeout = LEVIN_DEFAULT_TIMEOUT_PRECONFIGURED); + int invoke_async(int command, const std::string& in_buff, boost::uuids::uuid connection_id, const callback_t &cb, size_t timeout = LEVIN_DEFAULT_TIMEOUT_PRECONFIGURED); int notify(int command, const std::string& in_buff, boost::uuids::uuid connection_id); bool close(boost::uuids::uuid connection_id); bool update_connection_context(const t_connection_context& contxt); bool request_callback(boost::uuids::uuid connection_id); template - bool foreach_connection(callback_t cb); + bool foreach_connection(const callback_t &cb); template - bool for_connection(const boost::uuids::uuid &connection_id, callback_t cb); + bool for_connection(const boost::uuids::uuid &connection_id, const callback_t &cb); size_t get_connections_count(); void set_handler(levin_commands_handler* handler, void (*destroy)(levin_commands_handler*) = NULL); @@ -245,7 +245,7 @@ public: std::list > m_invoke_response_handlers; template - bool add_invoke_response_handler(callback_t cb, uint64_t timeout, async_protocol_handler& con, int command) + bool add_invoke_response_handler(const callback_t &cb, uint64_t timeout, async_protocol_handler& con, int command) { CRITICAL_REGION_LOCAL(m_invoke_response_handlers_lock); boost::shared_ptr handler(boost::make_shared>(cb, timeout, con, command)); @@ -529,7 +529,7 @@ public: } template - bool async_invoke(int command, const std::string& in_buff, callback_t cb, size_t timeout = LEVIN_DEFAULT_TIMEOUT_PRECONFIGURED) + bool async_invoke(int command, const std::string& in_buff, const callback_t &cb, size_t timeout = LEVIN_DEFAULT_TIMEOUT_PRECONFIGURED) { misc_utils::auto_scope_leave_caller scope_exit_handler = misc_utils::create_scope_leave_handler( boost::bind(&async_protocol_handler::finish_outer_call, this)); @@ -805,7 +805,7 @@ int async_protocol_handler_config::invoke(int command, con } //------------------------------------------------------------------------------------------ template template -int async_protocol_handler_config::invoke_async(int command, const std::string& in_buff, boost::uuids::uuid connection_id, callback_t cb, size_t timeout) +int async_protocol_handler_config::invoke_async(int command, const std::string& in_buff, boost::uuids::uuid connection_id, const callback_t &cb, size_t timeout) { async_protocol_handler* aph; int r = find_and_lock_connection(connection_id, aph); @@ -813,7 +813,7 @@ int async_protocol_handler_config::invoke_async(int comman } //------------------------------------------------------------------------------------------ template template -bool async_protocol_handler_config::foreach_connection(callback_t cb) +bool async_protocol_handler_config::foreach_connection(const callback_t &cb) { CRITICAL_REGION_LOCAL(m_connects_lock); for(auto& c: m_connects) @@ -826,7 +826,7 @@ bool async_protocol_handler_config::foreach_connection(cal } //------------------------------------------------------------------------------------------ template template -bool async_protocol_handler_config::for_connection(const boost::uuids::uuid &connection_id, callback_t cb) +bool async_protocol_handler_config::for_connection(const boost::uuids::uuid &connection_id, const callback_t &cb) { CRITICAL_REGION_LOCAL(m_connects_lock); async_protocol_handler* aph = find_connection(connection_id); diff --git a/contrib/epee/include/storages/levin_abstract_invoke2.h b/contrib/epee/include/storages/levin_abstract_invoke2.h index b4f7abca8..d77e7a1f8 100644 --- a/contrib/epee/include/storages/levin_abstract_invoke2.h +++ b/contrib/epee/include/storages/levin_abstract_invoke2.h @@ -108,7 +108,7 @@ namespace epee } template - bool async_invoke_remote_command2(boost::uuids::uuid conn_id, int command, const t_arg& out_struct, t_transport& transport, callback_t cb, size_t inv_timeout = LEVIN_DEFAULT_TIMEOUT_PRECONFIGURED) + bool async_invoke_remote_command2(boost::uuids::uuid conn_id, int command, const t_arg& out_struct, t_transport& transport, const callback_t &cb, size_t inv_timeout = LEVIN_DEFAULT_TIMEOUT_PRECONFIGURED) { typename serialization::portable_storage stg; const_cast(out_struct).store(stg);//TODO: add true const support to searilzation diff --git a/src/p2p/net_node.h b/src/p2p/net_node.h index 20520f83c..4f2d2b4cf 100644 --- a/src/p2p/net_node.h +++ b/src/p2p/net_node.h @@ -214,7 +214,7 @@ namespace nodetool void add_upnp_port_mapping(uint32_t port); void delete_upnp_port_mapping(uint32_t port); template - bool try_ping(basic_node_data& node_data, p2p_connection_context& context, t_callback cb); + bool try_ping(basic_node_data& node_data, p2p_connection_context& context, const t_callback &cb); bool try_get_support_flags(const p2p_connection_context& context, std::function f); bool make_expected_connections_count(PeerType peer_type, size_t expected_connections); void cache_connect_fail_info(const epee::net_utils::network_address& addr); diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index 152dba942..6e6e12009 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -1477,7 +1477,7 @@ namespace nodetool } //----------------------------------------------------------------------------------- template template - bool node_server::try_ping(basic_node_data& node_data, p2p_connection_context& context, t_callback cb) + bool node_server::try_ping(basic_node_data& node_data, p2p_connection_context& context, const t_callback &cb) { if(!node_data.my_port) return false; diff --git a/tests/core_tests/block_validation.cpp b/tests/core_tests/block_validation.cpp index b9818d2c5..598cd4098 100644 --- a/tests/core_tests/block_validation.cpp +++ b/tests/core_tests/block_validation.cpp @@ -38,7 +38,7 @@ namespace { bool lift_up_difficulty(std::vector& events, std::vector& timestamps, std::vector& cummulative_difficulties, test_generator& generator, - size_t new_block_count, const block blk_last, const account_base& miner_account) + size_t new_block_count, const block &blk_last, const account_base& miner_account) { difficulty_type commulative_diffic = cummulative_difficulties.empty() ? 0 : cummulative_difficulties.back(); block blk_prev = blk_last; From e4646379a6fb5d1dcff71cc38db5e60802a21dcb Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Wed, 7 Feb 2018 13:39:32 +0000 Subject: [PATCH 14/14] keccak: fix mdlen bounds sanity checking found by h908714124 --- src/crypto/keccak.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/crypto/keccak.c b/src/crypto/keccak.c index 7386d37a3..533021af3 100644 --- a/src/crypto/keccak.c +++ b/src/crypto/keccak.c @@ -81,7 +81,8 @@ void keccak(const uint8_t *in, size_t inlen, uint8_t *md, int mdlen) uint8_t temp[144]; size_t i, rsiz, rsizw; - if (mdlen <= 0 || mdlen > 200 || sizeof(st) != 200) + static_assert(HASH_DATA_AREA <= sizeof(temp), "Bad keccak preconditions"); + if (mdlen <= 0 || (mdlen > 100 && sizeof(st) != (size_t)mdlen)) { fprintf(stderr, "Bad keccak use"); abort();