cryptodev_digest_copy: return error if allocating dstate->mac_data fails
authorJonas Maebe <jonas.maebe@elis.ugent.be>
Sun, 8 Dec 2013 16:20:30 +0000 (17:20 +0100)
committerKurt Roeckx <kurt@roeckx.be>
Fri, 15 Aug 2014 20:38:51 +0000 (22:38 +0200)
Signed-off-by: Kurt Roeckx <kurt@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
crypto/engine/eng_cryptodev.c

index c823eebe7c0efb80b95cc4b1da49c972f7a99263..85bc1e854e683fe24329aa4c886413bd29034513 100644 (file)
@@ -901,17 +901,22 @@ static int cryptodev_digest_copy(EVP_MD_CTX *to,const EVP_MD_CTX *from)
        if (ioctl(dstate->d_fd, CIOCGSESSION, sess) < 0) {
                put_dev_crypto(dstate->d_fd);
                dstate->d_fd = -1;
-               printf("cryptodev_digest_init: Open session failed\n");
+               printf("cryptodev_digest_copy: Open session failed\n");
                return (0);
        }
 
        if (fstate->mac_len != 0) {
                if (fstate->mac_data != NULL)
-                       {
-                       dstate->mac_data = OPENSSL_malloc(fstate->mac_len);
-                       memcpy(dstate->mac_data, fstate->mac_data, fstate->mac_len);
-                       dstate->mac_len = fstate->mac_len;
-                       }
+                       {
+                       dstate->mac_data = OPENSSL_malloc(fstate->mac_len);
+                       if (dstate->mac_data == NULL)
+                               {
+                               printf("cryptodev_digest_copy: mac_data allocation failed\n");
+                               return (0);
+                               }
+                       memcpy(dstate->mac_data, fstate->mac_data, fstate->mac_len);
+                       dstate->mac_len = fstate->mac_len;
+                       }
        }
 
        return 1;