diff options
author | Jack Lloyd <[email protected]> | 2019-12-06 11:02:59 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2019-12-06 11:11:55 -0500 |
commit | ecb092d18aa6c87814bb63748d104910f4c27d6c (patch) | |
tree | 7eba92e6d0f3bd6fd834bab3a52e0d7f67ecfa7c /src/lib/ffi | |
parent | 74a8685830775c1463e3eb484e2faf824e6862cd (diff) |
Avoid MSVC warnings about dead code in FFI layer
Also fix warning about "insecure" getenv
Diffstat (limited to 'src/lib/ffi')
-rw-r--r-- | src/lib/ffi/ffi.cpp | 3 | ||||
-rw-r--r-- | src/lib/ffi/ffi_block.cpp | 4 | ||||
-rw-r--r-- | src/lib/ffi/ffi_cert.cpp | 10 | ||||
-rw-r--r-- | src/lib/ffi/ffi_cipher.cpp | 6 | ||||
-rw-r--r-- | src/lib/ffi/ffi_hotp.cpp | 2 | ||||
-rw-r--r-- | src/lib/ffi/ffi_mp.cpp | 14 | ||||
-rw-r--r-- | src/lib/ffi/ffi_pk_op.cpp | 2 | ||||
-rw-r--r-- | src/lib/ffi/ffi_pkey.cpp | 10 | ||||
-rw-r--r-- | src/lib/ffi/ffi_totp.cpp | 2 | ||||
-rw-r--r-- | src/lib/ffi/ffi_util.h | 11 |
10 files changed, 38 insertions, 26 deletions
diff --git a/src/lib/ffi/ffi.cpp b/src/lib/ffi/ffi.cpp index 58afb1c56..4600d5785 100644 --- a/src/lib/ffi/ffi.cpp +++ b/src/lib/ffi/ffi.cpp @@ -18,7 +18,8 @@ namespace Botan_FFI { int ffi_error_exception_thrown(const char* func_name, const char* exn, int rc) { - if(Botan::OS::read_env_variable("BOTAN_FFI_PRINT_EXCEPTIONS") != nullptr) + std::string val; + if(Botan::OS::read_env_variable(val, "BOTAN_FFI_PRINT_EXCEPTIONS") == true && val != "") { std::fprintf(stderr, "in %s exception '%s' returning %d\n", func_name, exn, rc); } diff --git a/src/lib/ffi/ffi_block.cpp b/src/lib/ffi/ffi_block.cpp index 71de6943b..fa5c25c57 100644 --- a/src/lib/ffi/ffi_block.cpp +++ b/src/lib/ffi/ffi_block.cpp @@ -61,8 +61,8 @@ int botan_block_cipher_set_key(botan_block_cipher_t bc, */ int botan_block_cipher_block_size(botan_block_cipher_t bc) { - return BOTAN_FFI_DO(Botan::BlockCipher, bc, b, - { return static_cast<int>(b.block_size()); }); + return BOTAN_FFI_RETURNING(Botan::BlockCipher, bc, b, + { return static_cast<int>(b.block_size()); }); } int botan_block_cipher_encrypt_blocks(botan_block_cipher_t bc, diff --git a/src/lib/ffi/ffi_cert.cpp b/src/lib/ffi/ffi_cert.cpp index 2aa6f5f3c..1baaa18d6 100644 --- a/src/lib/ffi/ffi_cert.cpp +++ b/src/lib/ffi/ffi_cert.cpp @@ -136,7 +136,7 @@ int botan_x509_cert_to_string(botan_x509_cert_t cert, char out[], size_t* out_le int botan_x509_cert_allowed_usage(botan_x509_cert_t cert, unsigned int key_usage) { #if defined(BOTAN_HAS_X509_CERTIFICATES) - return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, { + return BOTAN_FFI_RETURNING(Botan::X509_Certificate, cert, c, { const Botan::Key_Constraints k = static_cast<Botan::Key_Constraints>(key_usage); if(c.allowed_usage(k)) return BOTAN_FFI_SUCCESS; @@ -405,10 +405,8 @@ int botan_x509_crl_destroy(botan_x509_crl_t crl) int botan_x509_is_revoked(botan_x509_crl_t crl, botan_x509_cert_t cert) { #if defined(BOTAN_HAS_X509_CERTIFICATES) - return ffi_guard_thunk(__func__, [=]() -> int { - int result = BOTAN_FFI_DO(Botan::X509_CRL, crl, c, - { return c.is_revoked(safe_get(cert)) ? 0 : -1; }); - return result; + return BOTAN_FFI_RETURNING(Botan::X509_CRL, crl, c, { + return c.is_revoked(safe_get(cert)) ? 0 : -1; }); #else BOTAN_UNUSED(cert); @@ -417,7 +415,7 @@ int botan_x509_is_revoked(botan_x509_crl_t crl, botan_x509_cert_t cert) #endif } -BOTAN_PUBLIC_API(2,13) int botan_x509_cert_verify_with_crl( +int botan_x509_cert_verify_with_crl( int* result_code, botan_x509_cert_t cert, const botan_x509_cert_t* intermediates, diff --git a/src/lib/ffi/ffi_cipher.cpp b/src/lib/ffi/ffi_cipher.cpp index 3c74a524f..17f443c89 100644 --- a/src/lib/ffi/ffi_cipher.cpp +++ b/src/lib/ffi/ffi_cipher.cpp @@ -192,7 +192,7 @@ int botan_cipher_set_associated_data(botan_cipher_t cipher, const uint8_t* ad, size_t ad_len) { - return BOTAN_FFI_DO(Botan::Cipher_Mode, cipher, c, { + return BOTAN_FFI_RETURNING(Botan::Cipher_Mode, cipher, c, { if(Botan::AEAD_Mode* aead = dynamic_cast<Botan::AEAD_Mode*>(&c)) { aead->set_associated_data(ad, ad_len); @@ -204,7 +204,9 @@ int botan_cipher_set_associated_data(botan_cipher_t cipher, int botan_cipher_valid_nonce_length(botan_cipher_t cipher, size_t nl) { - return BOTAN_FFI_DO(Botan::Cipher_Mode, cipher, c, { return c.valid_nonce_length(nl) ? 1 : 0; }); + return BOTAN_FFI_RETURNING(Botan::Cipher_Mode, cipher, c, { + return c.valid_nonce_length(nl) ? 1 : 0; + }); } int botan_cipher_get_default_nonce_length(botan_cipher_t cipher, size_t* nl) diff --git a/src/lib/ffi/ffi_hotp.cpp b/src/lib/ffi/ffi_hotp.cpp index e1c4c40e8..779b7b128 100644 --- a/src/lib/ffi/ffi_hotp.cpp +++ b/src/lib/ffi/ffi_hotp.cpp @@ -80,7 +80,7 @@ int botan_hotp_check(botan_hotp_t hotp, size_t resync_range) { #if defined(BOTAN_HAS_HOTP) - return BOTAN_FFI_DO(Botan::HOTP, hotp, h, { + return BOTAN_FFI_RETURNING(Botan::HOTP, hotp, h, { auto resp = h.verify_hotp(hotp_code, hotp_counter, resync_range); diff --git a/src/lib/ffi/ffi_mp.cpp b/src/lib/ffi/ffi_mp.cpp index be94a2c3d..513dbbb0c 100644 --- a/src/lib/ffi/ffi_mp.cpp +++ b/src/lib/ffi/ffi_mp.cpp @@ -106,7 +106,7 @@ int botan_mp_to_hex(const botan_mp_t mp, char* out) int botan_mp_to_str(const botan_mp_t mp, uint8_t digit_base, char* out, size_t* out_len) { - return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { + return BOTAN_FFI_RETURNING(Botan::BigInt, mp, bn, { if(digit_base == 0 || digit_base == 10) return write_str_output(out, out_len, bn.to_dec_string()); @@ -199,22 +199,22 @@ int botan_mp_div(botan_mp_t quotient, int botan_mp_equal(const botan_mp_t x_w, const botan_mp_t y_w) { - return BOTAN_FFI_DO(Botan::BigInt, x_w, x, { return x == safe_get(y_w); }); + return BOTAN_FFI_RETURNING(Botan::BigInt, x_w, x, { return x == safe_get(y_w); }); } int botan_mp_is_zero(const botan_mp_t mp) { - return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { return bn.is_zero(); }); + return BOTAN_FFI_RETURNING(Botan::BigInt, mp, bn, { return bn.is_zero(); }); } int botan_mp_is_odd(const botan_mp_t mp) { - return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { return bn.is_odd(); }); + return BOTAN_FFI_RETURNING(Botan::BigInt, mp, bn, { return bn.is_odd(); }); } int botan_mp_is_even(const botan_mp_t mp) { - return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { return bn.is_even(); }); + return BOTAN_FFI_RETURNING(Botan::BigInt, mp, bn, { return bn.is_even(); }); } int botan_mp_cmp(int* result, const botan_mp_t x_w, const botan_mp_t y_w) @@ -280,13 +280,13 @@ int botan_mp_gcd(botan_mp_t out, const botan_mp_t x, const botan_mp_t y) int botan_mp_is_prime(const botan_mp_t mp, botan_rng_t rng, size_t test_prob) { - return BOTAN_FFI_DO(Botan::BigInt, mp, n, + return BOTAN_FFI_RETURNING(Botan::BigInt, mp, n, { return (Botan::is_prime(n, safe_get(rng), test_prob)) ? 1 : 0; }); } int botan_mp_get_bit(const botan_mp_t mp, size_t bit) { - return BOTAN_FFI_DO(Botan::BigInt, mp, n, { return (n.get_bit(bit)); }); + return BOTAN_FFI_RETURNING(Botan::BigInt, mp, n, { return (n.get_bit(bit)); }); } int botan_mp_set_bit(botan_mp_t mp, size_t bit) diff --git a/src/lib/ffi/ffi_pk_op.cpp b/src/lib/ffi/ffi_pk_op.cpp index 10fd379b4..525f28eeb 100644 --- a/src/lib/ffi/ffi_pk_op.cpp +++ b/src/lib/ffi/ffi_pk_op.cpp @@ -185,7 +185,7 @@ int botan_pk_op_verify_update(botan_pk_op_verify_t op, const uint8_t in[], size_ int botan_pk_op_verify_finish(botan_pk_op_verify_t op, const uint8_t sig[], size_t sig_len) { - return BOTAN_FFI_DO(Botan::PK_Verifier, op, o, { + return BOTAN_FFI_RETURNING(Botan::PK_Verifier, op, o, { const bool legit = o.check_signature(sig, sig_len); if(legit) diff --git a/src/lib/ffi/ffi_pkey.cpp b/src/lib/ffi/ffi_pkey.cpp index e0ba2380a..2fb3d338e 100644 --- a/src/lib/ffi/ffi_pkey.cpp +++ b/src/lib/ffi/ffi_pkey.cpp @@ -137,15 +137,17 @@ int botan_pubkey_check_key(botan_pubkey_t key, botan_rng_t rng, uint32_t flags) { const bool strong = (flags & BOTAN_CHECK_KEY_EXPENSIVE_TESTS); - return BOTAN_FFI_DO(Botan::Public_Key, key, k, - { return (k.check_key(safe_get(rng), strong) == true) ? 0 : BOTAN_FFI_ERROR_INVALID_INPUT; }); + return BOTAN_FFI_RETURNING(Botan::Public_Key, key, k, { + return (k.check_key(safe_get(rng), strong) == true) ? 0 : BOTAN_FFI_ERROR_INVALID_INPUT; + }); } int botan_privkey_check_key(botan_privkey_t key, botan_rng_t rng, uint32_t flags) { const bool strong = (flags & BOTAN_CHECK_KEY_EXPENSIVE_TESTS); - return BOTAN_FFI_DO(Botan::Private_Key, key, k, - { return (k.check_key(safe_get(rng), strong) == true) ? 0 : BOTAN_FFI_ERROR_INVALID_INPUT; }); + return BOTAN_FFI_RETURNING(Botan::Private_Key, key, k, { + return (k.check_key(safe_get(rng), strong) == true) ? 0 : BOTAN_FFI_ERROR_INVALID_INPUT; + }); } int botan_pubkey_export(botan_pubkey_t key, uint8_t out[], size_t* out_len, uint32_t flags) diff --git a/src/lib/ffi/ffi_totp.cpp b/src/lib/ffi/ffi_totp.cpp index c51f77954..4fd5dc94a 100644 --- a/src/lib/ffi/ffi_totp.cpp +++ b/src/lib/ffi/ffi_totp.cpp @@ -80,7 +80,7 @@ int botan_totp_check(botan_totp_t totp, size_t acceptable_clock_drift) { #if defined(BOTAN_HAS_TOTP) - return BOTAN_FFI_DO(Botan::TOTP, totp, t, { + return BOTAN_FFI_RETURNING(Botan::TOTP, totp, t, { const bool ok = t.verify_totp(totp_code, timestamp, acceptable_clock_drift); return (ok ? BOTAN_FFI_SUCCESS : BOTAN_FFI_INVALID_VERIFIER); }); diff --git a/src/lib/ffi/ffi_util.h b/src/lib/ffi/ffi_util.h index e77a2debb..4269aa3e8 100644 --- a/src/lib/ffi/ffi_util.h +++ b/src/lib/ffi/ffi_util.h @@ -89,10 +89,19 @@ int apply_fn(botan_struct<T, M>* o, const char* func_name, F func) return ffi_guard_thunk(func_name, [&]() { return func(*p); }); } -#define BOTAN_FFI_DO(T, obj, param, block) \ +#define BOTAN_FFI_DO(T, obj, param, block) \ apply_fn(obj, __func__, \ [=](T& param) -> int { do { block } while(0); return BOTAN_FFI_SUCCESS; }) +/* +* Like BOTAN_FFI_DO but with no trailing return with the expectation +* that the block always returns a value. This exists because otherwise +* MSVC warns about the dead return after the block in FFI_DO. +*/ +#define BOTAN_FFI_RETURNING(T, obj, param, block) \ + apply_fn(obj, __func__, \ + [=](T& param) -> int { do { block } while(0); }) + template<typename T, uint32_t M> int ffi_delete_object(botan_struct<T, M>* obj, const char* func_name) { |