File 0102-Fix-bug-for-aes_cfb_128_encrypt-with-empty-binary.patch of Package erlang

From 5e40dfbf957df2b64dc7e713c5c8fc83ea538f52 Mon Sep 17 00:00:00 2001
From: Sverker Eriksson <sverker@erlang.org>
Date: Thu, 9 Jul 2015 16:41:53 +0200
Subject: [PATCH 2/4] 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(-)

diff --git a/lib/crypto/c_src/crypto.c b/lib/crypto/c_src/crypto.c
index 595ee65..3add54b 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);
-- 
2.1.4

openSUSE Build Service is sponsored by