038bb32
diff -up openssl-1.0.2a/crypto/evp/bio_enc.c.enc-fail openssl-1.0.2a/crypto/evp/bio_enc.c
038bb32
--- openssl-1.0.2a/crypto/evp/bio_enc.c.enc-fail	2015-03-19 14:19:00.000000000 +0100
038bb32
+++ openssl-1.0.2a/crypto/evp/bio_enc.c	2015-04-22 18:10:06.491819948 +0200
038bb32
@@ -201,10 +201,14 @@ static int enc_read(BIO *b, char *out, i
038bb32
                 break;
038bb32
             }
038bb32
         } else {
038bb32
-            EVP_CipherUpdate(&(ctx->cipher),
038bb32
-                             (unsigned char *)ctx->buf, &ctx->buf_len,
038bb32
-                             (unsigned char *)&(ctx->buf[BUF_OFFSET]), i);
038bb32
-            ctx->cont = 1;
038bb32
+            if (!EVP_CipherUpdate(&(ctx->cipher),
038bb32
+                                  (unsigned char *)ctx->buf, &ctx->buf_len,
038bb32
+                                  (unsigned char *)&(ctx->buf[BUF_OFFSET]),
038bb32
+                                  i)) {
038bb32
+                ctx->ok = 0;
038bb32
+                ctx->cont = 0;
038bb32
+            } else
038bb32
+                ctx->cont = 1;
038bb32
             /*
038bb32
              * Note: it is possible for EVP_CipherUpdate to decrypt zero
038bb32
              * bytes because this is or looks like the final block: if this
038bb32
@@ -260,9 +264,13 @@ static int enc_write(BIO *b, const char
038bb32
     ctx->buf_off = 0;
038bb32
     while (inl > 0) {
038bb32
         n = (inl > ENC_BLOCK_SIZE) ? ENC_BLOCK_SIZE : inl;
038bb32
-        EVP_CipherUpdate(&(ctx->cipher),
038bb32
-                         (unsigned char *)ctx->buf, &ctx->buf_len,
038bb32
-                         (unsigned char *)in, n);
038bb32
+        if (!EVP_CipherUpdate(&(ctx->cipher),
038bb32
+                              (unsigned char *)ctx->buf, &ctx->buf_len,
038bb32
+                              (unsigned char *)in, n)) {
038bb32
+            BIO_copy_next_retry(b);
038bb32
+            ctx->ok = 0;
038bb32
+            return ret - inl;
038bb32
+        }
038bb32
         inl -= n;
038bb32
         in += n;
038bb32
 
038bb32
@@ -298,8 +306,9 @@ static long enc_ctrl(BIO *b, int cmd, lo
038bb32
     case BIO_CTRL_RESET:
038bb32
         ctx->ok = 1;
038bb32
         ctx->finished = 0;
038bb32
-        EVP_CipherInit_ex(&(ctx->cipher), NULL, NULL, NULL, NULL,
038bb32
-                          ctx->cipher.encrypt);
038bb32
+        if (!EVP_CipherInit_ex(&(ctx->cipher), NULL, NULL, NULL, NULL,
038bb32
+                               ctx->cipher.encrypt))
038bb32
+             ctx->ok = 0;
038bb32
         ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
038bb32
         break;
038bb32
     case BIO_CTRL_EOF:         /* More to read */
038bb32
@@ -421,7 +430,8 @@ void BIO_set_cipher(BIO *b, const EVP_CI
038bb32
 
038bb32
     b->init = 1;
038bb32
     ctx = (BIO_ENC_CTX *)b->ptr;
038bb32
-    EVP_CipherInit_ex(&(ctx->cipher), c, NULL, k, i, e);
038bb32
+    if (!EVP_CipherInit_ex(&(ctx->cipher), c, NULL, k, i, e))
038bb32
+        ctx->ok = 0;
038bb32
 
038bb32
     if (b->callback != NULL)
038bb32
         b->callback(b, BIO_CB_CTRL, (const char *)c, BIO_CTRL_SET, e, 1L);