From cc1462e0b7cc111943a2a3c7d525b362aca8a40a Mon Sep 17 00:00:00 2001 From: Ashley Perpetual Date: Fri, 27 Jan 2017 03:31:56 +0800 Subject: Add concurrency check to rpc mining to ensure not too many threads. number of cores times 4 or 257. --- src/rpc/core_rpc_server.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index 7d896e491..9782c7b83 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -616,6 +616,23 @@ namespace cryptonote return true; } + unsigned int concurrency_count = boost::thread::hardware_concurrency() * 4; + + // if we couldn't detect threads, set it to a ridiculously high number + if(concurrency_count == 0) + { + concurrency_count = 257; + } + + // if there are more threads requested than the hardware supports + // then we fail and log that. + if(req.threads_count > concurrency_count) + { + res.status = "Failed, too many threads relative to CPU cores."; + LOG_PRINT_L0(res.status); + return true; + } + boost::thread::attributes attrs; attrs.set_stack_size(THREAD_STACK_SIZE); -- cgit v1.2.3