From 5e40dfbf957df2b64dc7e713c5c8fc83ea538f52 Mon Sep 17 00:00:00 2001 From: Sverker Eriksson Date: Thu, 9 Jul 2015 16:41:53 +0200 Subject: Fix bug for aes_cfb_128_encrypt with empty binary causing OpenSSL 0.9.8h to crash with evp_enc.c(282): OpenSSL internal error, assertion failed: inl > 0 --- lib/crypto/c_src/crypto.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'lib/crypto') diff --git a/lib/crypto/c_src/crypto.c b/lib/crypto/c_src/crypto.c index 595ee65415..3add54bcd3 100644 --- a/lib/crypto/c_src/crypto.c +++ b/lib/crypto/c_src/crypto.c @@ -1332,10 +1332,15 @@ static ERL_NIF_TERM block_crypt_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM EVP_CIPHER_CTX_ctrl(&ctx, EVP_CTRL_SET_RC2_KEY_BITS, key.size * 8, NULL)) || !EVP_CipherInit_ex(&ctx, NULL, NULL, key.data, ivec_size ? ivec.data : NULL, -1) || - !EVP_CIPHER_CTX_set_padding(&ctx, 0) || - !EVP_CipherUpdate(&ctx, out, &out_size, text.data, text.size) || - (ASSERT(out_size == text.size), 0) || - !EVP_CipherFinal_ex(&ctx, out + out_size, &out_size)) { + !EVP_CIPHER_CTX_set_padding(&ctx, 0)) { + + return enif_raise_exception(env, atom_notsup); + } + + if (text.size > 0 && /* OpenSSL 0.9.8h asserts text.size > 0 */ + (!EVP_CipherUpdate(&ctx, out, &out_size, text.data, text.size) + || (ASSERT(out_size == text.size), 0) + || !EVP_CipherFinal_ex(&ctx, out + out_size, &out_size))) { EVP_CIPHER_CTX_cleanup(&ctx); return enif_raise_exception(env, atom_notsup); -- cgit v1.2.3