diff options
author | Kirill A. Korinsky <[email protected]> | 2017-06-29 13:36:52 +0400 |
---|---|---|
committer | Kirill A. Korinsky <[email protected]> | 2017-06-29 20:03:48 +0400 |
commit | e015fd1709b4b0c9cee7f8292f7e5ecd1b8d4ff7 (patch) | |
tree | e3d4a66f471204f389d96b91b3f2a56a643d93e1 /src/lib/prov/openssl/openssl_block.cpp | |
parent | 8b0986310ae9fdf7fa93e28e2820d818cc954cdd (diff) |
Don't crash if openssl can't allocate a new context
Diffstat (limited to 'src/lib/prov/openssl/openssl_block.cpp')
-rw-r--r-- | src/lib/prov/openssl/openssl_block.cpp | 10 |
1 files changed, 8 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)) |