diff options
author | Jack Lloyd <[email protected]> | 2015-12-19 16:09:17 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2015-12-19 16:09:17 -0500 |
commit | 0fae1884079518e4f6d1c049cc7f341cd96c8a65 (patch) | |
tree | 41e3a8aea10b7381c0e2cfd4ee019745215876ac | |
parent | b3da432772628fdb3eed9cf5dabb54eda0097d2b (diff) |
Remove all remaining uses of throwing a std:: exception directly
See GH #340 and 6b9a3a5 for background
-rw-r--r-- | src/cli/cc_enc.cpp | 2 | ||||
-rw-r--r-- | src/cli/cli.h | 7 | ||||
-rw-r--r-- | src/cli/tls_client.cpp | 12 | ||||
-rw-r--r-- | src/cli/tls_server.cpp | 12 | ||||
-rw-r--r-- | src/lib/base/scan_name.cpp | 2 | ||||
-rw-r--r-- | src/lib/compression/bzip2/bzip2.cpp | 12 | ||||
-rw-r--r-- | src/lib/compression/lzma/lzma.cpp | 6 | ||||
-rw-r--r-- | src/lib/compression/zlib/zlib.cpp | 6 | ||||
-rw-r--r-- | src/lib/misc/fpe_fe1/fpe_fe1.cpp | 2 | ||||
-rw-r--r-- | src/lib/pubkey/mce/gf2m_rootfind_dcmp.cpp | 3 | ||||
-rw-r--r-- | src/lib/tls/tls_policy.cpp | 2 |
11 files changed, 35 insertions, 31 deletions
diff --git a/src/cli/cc_enc.cpp b/src/cli/cc_enc.cpp index 25c9b960b..35932b487 100644 --- a/src/cli/cc_enc.cpp +++ b/src/cli/cc_enc.cpp @@ -75,7 +75,7 @@ uint64_t encrypt_cc_number(uint64_t cc_number, const Botan::BigInt c = Botan::FPE::fe1_encrypt(n, cc_ranked, key, tweak); if(c.bits() > 50) - throw std::runtime_error("FPE produced a number too large"); + throw Botan::Internal_Error("FPE produced a number too large"); uint64_t enc_cc = 0; for(size_t i = 0; i != 7; ++i) diff --git a/src/cli/cli.h b/src/cli/cli.h index b2be2bd39..d079afbc5 100644 --- a/src/cli/cli.h +++ b/src/cli/cli.h @@ -9,6 +9,8 @@ #include <botan/build.h> #include <botan/parsing.h> +#include <botan/rng.h> + #include <fstream> #include <iostream> #include <functional> @@ -492,10 +494,11 @@ class Command if(reg.count(name) > 0) { - throw std::logic_error("Duplicated registration of command " + name); + throw CLI_Error("Duplicated registration of command " + name); } - Command::global_registry().insert(std::make_pair(name, std::unique_ptr<Command>(cmd))); + Command::global_registry().insert( + std::make_pair(name, std::unique_ptr<Command>(cmd))); } }; }; diff --git a/src/cli/tls_client.cpp b/src/cli/tls_client.cpp index c13e9019e..1f69473c1 100644 --- a/src/cli/tls_client.cpp +++ b/src/cli/tls_client.cpp @@ -198,16 +198,16 @@ class TLS_Client : public Command hostent* host_addr = ::gethostbyname(host.c_str()); if(!host_addr) - throw std::runtime_error("gethostbyname failed for " + host); + throw CLI_Error("gethostbyname failed for " + host); if(host_addr->h_addrtype != AF_INET) // FIXME - throw std::runtime_error(host + " has IPv6 address, not supported"); + throw CLI_Error(host + " has IPv6 address, not supported"); int type = tcp ? SOCK_STREAM : SOCK_DGRAM; int fd = ::socket(PF_INET, type, 0); if(fd == -1) - throw std::runtime_error("Unable to acquire socket"); + throw CLI_Error("Unable to acquire socket"); sockaddr_in socket_info; ::memset(&socket_info, 0, sizeof(socket_info)); @@ -223,7 +223,7 @@ class TLS_Client : public Command if(::connect(fd, (sockaddr*)&socket_info, sizeof(struct sockaddr)) != 0) { ::close(fd); - throw std::runtime_error("connect failed"); + throw CLI_Error("connect failed"); } return fd; @@ -248,7 +248,7 @@ class TLS_Client : public Command int r = send(sockfd, buf, length, MSG_NOSIGNAL); if(r == -1) - throw std::runtime_error("Socket write failed errno=" + std::to_string(errno)); + throw CLI_Error("Socket write failed errno=" + std::to_string(errno)); } static void stream_socket_write(int sockfd, const uint8_t buf[], size_t length) @@ -265,7 +265,7 @@ class TLS_Client : public Command if(errno == EINTR) sent = 0; else - throw std::runtime_error("Socket write failed errno=" + std::to_string(errno)); + throw CLI_Error("Socket write failed errno=" + std::to_string(errno)); } offset += sent; diff --git a/src/cli/tls_server.cpp b/src/cli/tls_server.cpp index 6a5b4e812..f6a3a311e 100644 --- a/src/cli/tls_server.cpp +++ b/src/cli/tls_server.cpp @@ -79,10 +79,10 @@ class TLS_Server : public Command if(::recvfrom(server_fd, nullptr, 0, MSG_PEEK, (struct sockaddr*)&from, &from_len) != 0) - throw std::runtime_error("Could not peek next packet"); + throw CLI_Error("Could not peek next packet"); if(::connect(server_fd, (struct sockaddr*)&from, from_len) != 0) - throw std::runtime_error("Could not connect UDP socket"); + throw CLI_Error("Could not connect UDP socket"); fd = server_fd; } @@ -161,7 +161,7 @@ class TLS_Server : public Command int fd = ::socket(PF_INET, type, 0); if(fd == -1) - throw std::runtime_error("Unable to acquire socket"); + throw CLI_Error("Unable to acquire socket"); sockaddr_in socket_info; ::memset(&socket_info, 0, sizeof(socket_info)); @@ -174,7 +174,7 @@ class TLS_Server : public Command if(::bind(fd, (sockaddr*)&socket_info, sizeof(struct sockaddr)) != 0) { ::close(fd); - throw std::runtime_error("server bind failed"); + throw CLI_Error("server bind failed"); } if(is_tcp) @@ -182,7 +182,7 @@ class TLS_Server : public Command if(::listen(fd, 100) != 0) { ::close(fd); - throw std::runtime_error("listen failed"); + throw CLI_Error("listen failed"); } } @@ -224,7 +224,7 @@ class TLS_Server : public Command if(errno == EINTR) sent = 0; else - throw std::runtime_error("Socket write failed"); + throw CLI_Error("Socket write failed"); } buf += sent; diff --git a/src/lib/base/scan_name.cpp b/src/lib/base/scan_name.cpp index 6f5eac43c..2b32dc7d3 100644 --- a/src/lib/base/scan_name.cpp +++ b/src/lib/base/scan_name.cpp @@ -155,7 +155,7 @@ std::string SCAN_Name::all_arguments() const std::string SCAN_Name::arg(size_t i) const { if(i >= arg_count()) - throw std::range_error("SCAN_Name::arg " + std::to_string(i) + + throw Invalid_Argument("SCAN_Name::arg " + std::to_string(i) + " out of range for '" + as_string() + "'"); return args[i]; } diff --git a/src/lib/compression/bzip2/bzip2.cpp b/src/lib/compression/bzip2/bzip2.cpp index d7527bfef..09cd05919 100644 --- a/src/lib/compression/bzip2/bzip2.cpp +++ b/src/lib/compression/bzip2/bzip2.cpp @@ -42,7 +42,7 @@ class Bzip2_Compression_Stream : public Bzip2_Stream int rc = BZ2_bzCompressInit(streamp(), block_size, 0, 0); if(rc == BZ_MEM_ERROR) - throw std::bad_alloc(); + throw Exception("bzip memory allocation failure"); else if(rc != BZ_OK) throw Exception("bzip compress initialization failed"); } @@ -57,9 +57,9 @@ class Bzip2_Compression_Stream : public Bzip2_Stream int rc = BZ2_bzCompress(streamp(), flags); if(rc == BZ_MEM_ERROR) - throw std::bad_alloc(); + throw Exception("bzip memory allocation failure"); else if(rc < 0) - throw Exception("bzip compress error"); + throw Exception("bzip compress error " + std::to_string(-rc)); return (rc == BZ_STREAM_END); } @@ -73,7 +73,7 @@ class Bzip2_Decompression_Stream : public Bzip2_Stream int rc = BZ2_bzDecompressInit(streamp(), 0, 0); if(rc == BZ_MEM_ERROR) - throw std::bad_alloc(); + throw Exception("bzip memory allocation failure"); else if(rc != BZ_OK) throw Exception("bzip decompress initialization failed"); } @@ -88,9 +88,9 @@ class Bzip2_Decompression_Stream : public Bzip2_Stream int rc = BZ2_bzDecompress(streamp()); if(rc == BZ_MEM_ERROR) - throw std::bad_alloc(); + throw Exception("bzip memory allocation failure"); else if(rc != BZ_OK && rc != BZ_STREAM_END) - throw Exception("bzip decompress error"); + throw Exception("bzip decompress error " + std::to_string(-rc)); return (rc == BZ_STREAM_END); } diff --git a/src/lib/compression/lzma/lzma.cpp b/src/lib/compression/lzma/lzma.cpp index 6e5217767..5998d1c8c 100644 --- a/src/lib/compression/lzma/lzma.cpp +++ b/src/lib/compression/lzma/lzma.cpp @@ -41,7 +41,7 @@ class LZMA_Stream : public Zlib_Style_Stream<lzma_stream, byte> lzma_ret rc = ::lzma_code(streamp(), static_cast<lzma_action>(flags)); if(rc == LZMA_MEM_ERROR) - throw std::bad_alloc(); + throw Exception("lzma memory allocation failed"); else if (rc != LZMA_OK && rc != LZMA_STREAM_END) throw Exception("Lzma error"); @@ -61,7 +61,7 @@ class LZMA_Compression_Stream : public LZMA_Stream lzma_ret rc = ::lzma_easy_encoder(streamp(), level, LZMA_CHECK_CRC64); if(rc == LZMA_MEM_ERROR) - throw std::bad_alloc(); + throw Exception("lzma memory allocation failed"); else if(rc != LZMA_OK) throw Exception("lzma compress initialization failed"); } @@ -76,7 +76,7 @@ class LZMA_Decompression_Stream : public LZMA_Stream LZMA_TELL_UNSUPPORTED_CHECK); if(rc == LZMA_MEM_ERROR) - throw std::bad_alloc(); + throw Exception("lzma memory allocation failed"); else if(rc != LZMA_OK) throw Exception("Bad setting in lzma_stream_decoder"); } diff --git a/src/lib/compression/zlib/zlib.cpp b/src/lib/compression/zlib/zlib.cpp index 10422fff7..8e1928826 100644 --- a/src/lib/compression/zlib/zlib.cpp +++ b/src/lib/compression/zlib/zlib.cpp @@ -66,7 +66,7 @@ class Zlib_Compression_Stream : public Zlib_Stream int rc = deflate(streamp(), flags); if(rc == Z_MEM_ERROR) - throw std::bad_alloc(); + throw Exception("zlib memory allocation failure"); else if(rc != Z_OK && rc != Z_STREAM_END && rc != Z_BUF_ERROR) throw Exception("zlib deflate error " + std::to_string(rc)); @@ -82,7 +82,7 @@ class Zlib_Decompression_Stream : public Zlib_Stream int rc = inflateInit2(streamp(), compute_window_bits(wbits, wbits_offset)); if(rc == Z_MEM_ERROR) - throw std::bad_alloc(); + throw Exception("zlib memory allocation failure"); else if(rc != Z_OK) throw Exception("zlib inflate initialization failed"); } @@ -97,7 +97,7 @@ class Zlib_Decompression_Stream : public Zlib_Stream int rc = inflate(streamp(), flags); if(rc == Z_MEM_ERROR) - throw std::bad_alloc(); + throw Exception("zlib memory allocation failure"); else if(rc != Z_OK && rc != Z_STREAM_END && rc != Z_BUF_ERROR) throw Exception("zlib inflate error " + std::to_string(rc)); diff --git a/src/lib/misc/fpe_fe1/fpe_fe1.cpp b/src/lib/misc/fpe_fe1/fpe_fe1.cpp index fad17c814..197dbb21a 100644 --- a/src/lib/misc/fpe_fe1/fpe_fe1.cpp +++ b/src/lib/misc/fpe_fe1/fpe_fe1.cpp @@ -68,7 +68,7 @@ void factor(BigInt n, BigInt& a, BigInt& b) size_t rounds(const BigInt& a, const BigInt& b) { if(a < b) - throw std::logic_error("FPE rounds: a < b"); + throw Internal_Error("FPE rounds: a < b"); return 3; } diff --git a/src/lib/pubkey/mce/gf2m_rootfind_dcmp.cpp b/src/lib/pubkey/mce/gf2m_rootfind_dcmp.cpp index d23d05172..3a377a447 100644 --- a/src/lib/pubkey/mce/gf2m_rootfind_dcmp.cpp +++ b/src/lib/pubkey/mce/gf2m_rootfind_dcmp.cpp @@ -9,6 +9,7 @@ #include <botan/polyn_gf2m.h> #include <botan/internal/bit_ops.h> #include <botan/internal/code_based_util.h> +#include <botan/exceptn.h> namespace Botan { @@ -102,7 +103,7 @@ gf2m_decomp_rootfind_state::gf2m_decomp_rootfind_state(const polyn_gf2m & polyn, int deg_sigma = polyn.get_degree(); if(deg_sigma <= 3) { - throw std::exception(); + throw Internal_Error("Unexpected degree in gf2m_decomp_rootfind_state"); } this->m_j = 0; coeff_3 = polyn.get_coef( 3); diff --git a/src/lib/tls/tls_policy.cpp b/src/lib/tls/tls_policy.cpp index 7d1af71ef..374c5f12b 100644 --- a/src/lib/tls/tls_policy.cpp +++ b/src/lib/tls/tls_policy.cpp @@ -306,7 +306,7 @@ std::vector<u16bit> Policy::ciphersuite_list(Protocol_Version version, } if(ciphersuites.empty()) - throw std::logic_error("Policy does not allow any available cipher suite"); + throw Exception("Policy does not allow any available cipher suite"); std::vector<u16bit> ciphersuite_codes; for(auto i : ciphersuites) |