RT3246: req command prints version number wrong
[oweals/openssl.git] / crypto / engine / eng_cryptodev.c
index 568e13161547f8af5e879891b08ff5b18c754860..85bc1e854e683fe24329aa4c886413bd29034513 100644 (file)
@@ -765,6 +765,7 @@ static int cryptodev_digest_update(EVP_MD_CTX *ctx, const void *data,
        struct crypt_op cryp;
        struct dev_crypto_state *state = ctx->md_data;
        struct session_op *sess = &state->d_sess;
+       char *new_mac_data;
 
        if (!data || state->d_fd < 0) {
                printf("cryptodev_digest_update: illegal inputs \n");
@@ -777,12 +778,13 @@ static int cryptodev_digest_update(EVP_MD_CTX *ctx, const void *data,
 
        if (!(ctx->flags & EVP_MD_CTX_FLAG_ONESHOT)) {
                /* if application doesn't support one buffer */
-               state->mac_data = OPENSSL_realloc(state->mac_data, state->mac_len + count);
+               new_mac_data = OPENSSL_realloc(state->mac_data, state->mac_len + count);
 
-               if (!state->mac_data) {
+               if (!new_mac_data) {
                        printf("cryptodev_digest_update: realloc failed\n");
                        return (0);
                }
+               state->mac_data = new_mac_data;
 
                memcpy(state->mac_data + state->mac_len, data, count);
                state->mac_len += count;
@@ -899,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;