fixed crash when encrypted streams are empty

Sun, 10 Apr 2016 11:39:09 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 10 Apr 2016 11:39:09 +0200
changeset 237
fd9135bc7580
parent 236
6b4ce32d0c4e
child 238
b167226fb804

fixed crash when encrypted streams are empty

libidav/crypto.c file | annotate | diff | comparison | revisions
--- a/libidav/crypto.c	Wed Mar 23 19:03:48 2016 +0100
+++ b/libidav/crypto.c	Sun Apr 10 11:39:09 2016 +0200
@@ -97,13 +97,15 @@
 }
 
 void aes_decrypter_shutdown(AESDecrypter *dec) {
-    void *out = malloc(128);
-    int len = 0;
-    EVP_DecryptFinal_ex(&dec->ctx, out, &len);
-    dec->write(out, 1, len, dec->stream);
-    SHA256_Update(&dec->sha256, out, len);
-    free(out);
-    EVP_CIPHER_CTX_cleanup(&dec->ctx);
+    if(dec->init) {
+        void *out = malloc(128);
+        int len = 0;
+        EVP_DecryptFinal_ex(&dec->ctx, out, &len);
+        dec->write(out, 1, len, dec->stream);
+        SHA256_Update(&dec->sha256, out, len);
+        free(out);
+        EVP_CIPHER_CTX_cleanup(&dec->ctx);
+    }
 }
 
 void aes_decrypter_close(AESDecrypter *dec) {

mercurial