diff options
author | Jack Lloyd <[email protected]> | 2018-03-16 12:01:01 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2018-03-16 12:01:01 -0400 |
commit | 6c8ffb4d2ee1f762804fc8d6a90a3d1761462503 (patch) | |
tree | 2b88c8d5a809cca03f3f66e6c1a053b1b7fa338a | |
parent | f787047f33d073036883b609d293656510ce8b16 (diff) |
Catch exceptions by reference not value
Fixes a new warning in GCC 8
-rw-r--r-- | src/lib/kdf/prf_tls/prf_tls.cpp | 2 | ||||
-rw-r--r-- | src/lib/pk_pad/emsa1/emsa1.cpp | 28 | ||||
-rw-r--r-- | src/lib/pubkey/ec_group/ec_group.cpp | 2 | ||||
-rw-r--r-- | src/lib/tls/tls_record.cpp | 2 | ||||
-rw-r--r-- | src/tests/test_cryptobox.cpp | 4 | ||||
-rw-r--r-- | src/tests/test_keywrap.cpp | 2 | ||||
-rw-r--r-- | src/tests/test_utils.cpp | 2 |
7 files changed, 18 insertions, 24 deletions
diff --git a/src/lib/kdf/prf_tls/prf_tls.cpp b/src/lib/kdf/prf_tls/prf_tls.cpp index 69383e98e..d914df77e 100644 --- a/src/lib/kdf/prf_tls/prf_tls.cpp +++ b/src/lib/kdf/prf_tls/prf_tls.cpp @@ -29,7 +29,7 @@ void P_hash(uint8_t out[], size_t out_len, { mac.set_key(secret, secret_len); } - catch(Invalid_Key_Length) + catch(Invalid_Key_Length&) { throw Internal_Error("The premaster secret of " + std::to_string(secret_len) + diff --git a/src/lib/pk_pad/emsa1/emsa1.cpp b/src/lib/pk_pad/emsa1/emsa1.cpp index b4391b48d..66d8ec852 100644 --- a/src/lib/pk_pad/emsa1/emsa1.cpp +++ b/src/lib/pk_pad/emsa1/emsa1.cpp @@ -77,29 +77,23 @@ bool EMSA1::verify(const secure_vector<uint8_t>& input, const secure_vector<uint8_t>& raw, size_t key_bits) { - try { - if(raw.size() != m_hash->output_length()) - throw Encoding_Error("EMSA1::encoding_of: Invalid size for input"); + if(raw.size() != m_hash->output_length()) + return false; - // Call emsa1_encoding to handle any required bit shifting - const secure_vector<uint8_t> our_coding = emsa1_encoding(raw, key_bits); + // Call emsa1_encoding to handle any required bit shifting + const secure_vector<uint8_t> our_coding = emsa1_encoding(raw, key_bits); - if(our_coding.size() < input.size()) - return false; + if(our_coding.size() < input.size()) + return false; - const size_t offset = our_coding.size() - input.size(); // must be >= 0 per check above + const size_t offset = our_coding.size() - input.size(); // must be >= 0 per check above - // If our encoding is longer, all the bytes in it must be zero - for(size_t i = 0; i != offset; ++i) - if(our_coding[i] != 0) + // If our encoding is longer, all the bytes in it must be zero + for(size_t i = 0; i != offset; ++i) + if(our_coding[i] != 0) return false; - return constant_time_compare(input.data(), &our_coding[offset], input.size()); - } - catch(Invalid_Argument) - { - return false; - } + return constant_time_compare(input.data(), &our_coding[offset], input.size()); } AlgorithmIdentifier EMSA1::config_for_x509(const Private_Key& key, diff --git a/src/lib/pubkey/ec_group/ec_group.cpp b/src/lib/pubkey/ec_group/ec_group.cpp index ccf1969d2..50a4d85c7 100644 --- a/src/lib/pubkey/ec_group/ec_group.cpp +++ b/src/lib/pubkey/ec_group/ec_group.cpp @@ -319,7 +319,7 @@ EC_Group::EC_Group(const std::string& str) if(oid.empty() == false) m_data = ec_group_data().lookup(oid); } - catch(Invalid_OID) + catch(Invalid_OID&) { } diff --git a/src/lib/tls/tls_record.cpp b/src/lib/tls/tls_record.cpp index 8c86ef3c7..8997c319a 100644 --- a/src/lib/tls/tls_record.cpp +++ b/src/lib/tls/tls_record.cpp @@ -476,7 +476,7 @@ size_t read_dtls_record(secure_vector<uint8_t>& readbuf, *rec.get_type(), *cs); } - catch(std::exception) + catch(std::exception&) { readbuf.clear(); *rec.get_type() = NO_RECORD; diff --git a/src/tests/test_cryptobox.cpp b/src/tests/test_cryptobox.cpp index 6d1d22314..5e7fcf08a 100644 --- a/src/tests/test_cryptobox.cpp +++ b/src/tests/test_cryptobox.cpp @@ -52,11 +52,11 @@ class Cryptobox_Tests final : public Test Botan::CryptoBox::decrypt(corrupted, password); result.test_failure("Decrypted corrupted cryptobox message"); } - catch(Botan::Decoding_Error) + catch(Botan::Decoding_Error&) { result.test_success("Rejected corrupted cryptobox message"); } - catch(Botan::Invalid_Argument) + catch(Botan::Invalid_Argument&) { result.test_success("Rejected corrupted cryptobox message"); } diff --git a/src/tests/test_keywrap.cpp b/src/tests/test_keywrap.cpp index a5b216562..de63d8067 100644 --- a/src/tests/test_keywrap.cpp +++ b/src/tests/test_keywrap.cpp @@ -160,7 +160,7 @@ class NIST_Keywrap_Invalid_Tests final : public Text_Based_Test result.test_failure("Was able to unwrap invalid keywrap input"); } - catch(Botan::Integrity_Failure) + catch(Botan::Integrity_Failure&) { result.test_success("Rejected invalid input"); } diff --git a/src/tests/test_utils.cpp b/src/tests/test_utils.cpp index c17acac57..5f3502eba 100644 --- a/src/tests/test_utils.cpp +++ b/src/tests/test_utils.cpp @@ -51,7 +51,7 @@ class Utility_Function_Tests final : public Text_Based_Test Botan::round_up(x, 0); result.test_failure("round_up did not reject invalid input"); } - catch(std::exception) {} + catch(std::exception&) {} } else if(algo == "round_down") { |