fix: Properly check error conditions for int-returning functions.

OpenSSL functions returning an int like `EVP_PKEY_derive_init` return
non-positive (0 or negative) integers on an error condition, so we need
to check for both.

See e.g. https://www.openssl.org/docs/man1.1.1/man3/EVP_PKEY_derive.html
This commit is contained in:
Denis Kasak 2021-12-14 21:57:34 +01:00
parent b82dab50c9
commit a02f3d9f82

View file

@ -34,13 +34,21 @@ static const std::size_t SHA256_BLOCK_LENGTH = 64;
static const std::uint8_t HKDF_DEFAULT_SALT[32] = {}; static const std::uint8_t HKDF_DEFAULT_SALT[32] = {};
template <typename T> template <typename T>
static T checked(T val) { inline T checked(T val) {
if (!val) { if (!val) {
abort(); abort();
} }
return val; return val;
} }
template <>
inline int checked(int val) {
if (val <= 0) {
abort();
}
return val;
}
} // namespace } // namespace
void _olm_crypto_curve25519_generate_key( void _olm_crypto_curve25519_generate_key(