From a02f3d9f824ac4d2fc333c5c0cf83ff4317c60f6 Mon Sep 17 00:00:00 2001 From: Denis Kasak Date: Tue, 14 Dec 2021 21:57:34 +0100 Subject: [PATCH] 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 --- src/crypto.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/crypto.cpp b/src/crypto.cpp index 99f47e9..cb7ac6b 100644 --- a/src/crypto.cpp +++ b/src/crypto.cpp @@ -34,13 +34,21 @@ static const std::size_t SHA256_BLOCK_LENGTH = 64; static const std::uint8_t HKDF_DEFAULT_SALT[32] = {}; template -static T checked(T val) { +inline T checked(T val) { if (!val) { abort(); } return val; } +template <> +inline int checked(int val) { + if (val <= 0) { + abort(); + } + return val; +} + } // namespace void _olm_crypto_curve25519_generate_key(