aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/prov/openssl
diff options
context:
space:
mode:
authorKirill A. Korinsky <[email protected]>2017-06-29 13:36:52 +0400
committerKirill A. Korinsky <[email protected]>2017-06-29 20:03:48 +0400
commite015fd1709b4b0c9cee7f8292f7e5ecd1b8d4ff7 (patch)
treee3d4a66f471204f389d96b91b3f2a56a643d93e1 /src/lib/prov/openssl
parent8b0986310ae9fdf7fa93e28e2820d818cc954cdd (diff)
Don't crash if openssl can't allocate a new context
Diffstat (limited to 'src/lib/prov/openssl')
-rw-r--r--src/lib/prov/openssl/openssl_block.cpp10
-rw-r--r--src/lib/prov/openssl/openssl_hash.cpp2
-rw-r--r--src/lib/prov/openssl/openssl_mode.cpp3
3 files changed, 13 insertions, 2 deletions
diff --git a/src/lib/prov/openssl/openssl_block.cpp b/src/lib/prov/openssl/openssl_block.cpp
index 5d5cf0b47..122678b6d 100644
--- a/src/lib/prov/openssl/openssl_block.cpp
+++ b/src/lib/prov/openssl/openssl_block.cpp
@@ -67,8 +67,11 @@ OpenSSL_BlockCipher::OpenSSL_BlockCipher(const std::string& algo_name,
throw Invalid_Argument("OpenSSL_BlockCipher: Non-ECB EVP was passed in");
m_encrypt = EVP_CIPHER_CTX_new();
- EVP_CIPHER_CTX_init(m_encrypt);
m_decrypt = EVP_CIPHER_CTX_new();
+ if (m_encrypt == nullptr || m_decrypt == nullptr)
+ throw OpenSSL_Error("Can't allocate new context");
+
+ EVP_CIPHER_CTX_init(m_encrypt);
EVP_CIPHER_CTX_init(m_decrypt);
if(!EVP_EncryptInit_ex(m_encrypt, algo, nullptr, nullptr, nullptr))
@@ -95,8 +98,11 @@ OpenSSL_BlockCipher::OpenSSL_BlockCipher(const std::string& algo_name,
throw Invalid_Argument("OpenSSL_BlockCipher: Non-ECB EVP was passed in");
m_encrypt = EVP_CIPHER_CTX_new();
- EVP_CIPHER_CTX_init(m_encrypt);
m_decrypt = EVP_CIPHER_CTX_new();
+ if (m_encrypt == nullptr || m_decrypt == nullptr)
+ throw OpenSSL_Error("Can't allocate new context");
+
+ EVP_CIPHER_CTX_init(m_encrypt);
EVP_CIPHER_CTX_init(m_decrypt);
if(!EVP_EncryptInit_ex(m_encrypt, algo, nullptr, nullptr, nullptr))
diff --git a/src/lib/prov/openssl/openssl_hash.cpp b/src/lib/prov/openssl/openssl_hash.cpp
index d7a8014a8..16b1a79fe 100644
--- a/src/lib/prov/openssl/openssl_hash.cpp
+++ b/src/lib/prov/openssl/openssl_hash.cpp
@@ -58,6 +58,8 @@ class OpenSSL_HashFunction : public HashFunction
m_md = EVP_MD_CTX_new();
#endif
+ if(m_md == nullptr)
+ throw OpenSSL_Error("Can't allocate new context");
EVP_MD_CTX_init(m_md);
if(md && !EVP_DigestInit_ex(m_md, md, nullptr))
throw OpenSSL_Error("EVP_DigestInit_ex");
diff --git a/src/lib/prov/openssl/openssl_mode.cpp b/src/lib/prov/openssl/openssl_mode.cpp
index 36f19eaec..bbb193feb 100644
--- a/src/lib/prov/openssl/openssl_mode.cpp
+++ b/src/lib/prov/openssl/openssl_mode.cpp
@@ -59,6 +59,9 @@ OpenSSL_Cipher_Mode::OpenSSL_Cipher_Mode(const std::string& name,
throw Invalid_Argument("OpenSSL_BlockCipher: Non-CBC EVP was passed in");
m_cipher = EVP_CIPHER_CTX_new();
+ if (m_cipher == nullptr)
+ throw OpenSSL_Error("Can't allocate new context");
+
EVP_CIPHER_CTX_init(m_cipher);
if(!EVP_CipherInit_ex(m_cipher, algo, nullptr, nullptr, nullptr,
m_direction == ENCRYPTION ? 1 : 0))