From 5736237a63d3183462bd3ca5a2365c895120c719 Mon Sep 17 00:00:00 2001 From: arvidn Date: Mon, 16 Jan 2017 09:50:56 -0500 Subject: [PATCH] fix error handling in random.cpp and fix accidental openssl dependency --- include/libtorrent/aux_/dev_random.hpp | 2 +- include/libtorrent/error_code.hpp | 3 +++ src/error_code.cpp | 4 ++++ src/random.cpp | 6 ++---- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/include/libtorrent/aux_/dev_random.hpp b/include/libtorrent/aux_/dev_random.hpp index b8ea3c9e8..91b787aba 100644 --- a/include/libtorrent/aux_/dev_random.hpp +++ b/include/libtorrent/aux_/dev_random.hpp @@ -62,7 +62,7 @@ namespace libtorrent { namespace aux { if (ret != buffer.size()) { #ifndef BOOST_NO_EXCEPTIONS - throw system_error(error_code(EIO, system_category())); + throw system_error(errors::no_entropy); #else std::terminate(); #endif diff --git a/include/libtorrent/error_code.hpp b/include/libtorrent/error_code.hpp index e4ca307b4..4c551e376 100644 --- a/include/libtorrent/error_code.hpp +++ b/include/libtorrent/error_code.hpp @@ -433,6 +433,9 @@ namespace libtorrent overflow, #endif + // random number generation failed + no_entropy = 200, + // the number of error codes error_code_max }; diff --git a/src/error_code.cpp b/src/error_code.cpp index 31108fcfa..4cebbc13c 100644 --- a/src/error_code.cpp +++ b/src/error_code.cpp @@ -263,7 +263,11 @@ namespace libtorrent "bencoded nesting depth exceeded", "bencoded item count limit exceeded", "integer overflow", + "", + "", + "", #endif + "random number generator failed", }; if (ev < 0 || ev >= int(sizeof(msgs)/sizeof(msgs[0]))) return "Unknown error"; diff --git a/src/random.cpp b/src/random.cpp index 55a4aed6d..6d918874a 100644 --- a/src/random.cpp +++ b/src/random.cpp @@ -41,13 +41,12 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/aux_/win_crypto_provider.hpp" #elif defined TORRENT_USE_LIBCRYPTO + extern "C" { #include #include } -#include - #endif #include "libtorrent/aux_/disable_warnings_pop.hpp" @@ -98,8 +97,7 @@ namespace libtorrent if (r != 1) { #ifndef BOOST_NO_EXCEPTIONS - throw system_error(error_code(int(::ERR_get_error()) - , boost::asio::error::get_ssl_category())); + throw system_error(errors::no_entropy); #else std::terminate(); #endif