Fix possible memory leak in cryptodev_digest_update.
authorBernd Edlinger <bernd.edlinger@hotmail.de>
Wed, 15 Feb 2017 18:11:05 +0000 (19:11 +0100)
committerBernd Edlinger <bernd.edlinger@hotmail.de>
Wed, 15 Feb 2017 18:11:05 +0000 (19:11 +0100)
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/2639)

crypto/engine/eng_cryptodev.c

index 2a2b95ce837e24a1ab528e98c0ef65e7060db421..af59471c4771cfd5d4c64d81eeee5bdd6d2930b7 100644 (file)
@@ -810,14 +810,15 @@ 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 =
+        char *mac_data =
             OPENSSL_realloc(state->mac_data, state->mac_len + count);
 
-        if (!state->mac_data) {
+        if (mac_data == NULL) {
             printf("cryptodev_digest_update: realloc failed\n");
             return (0);
         }
 
+        state->mac_data = mac_data;
         memcpy(state->mac_data + state->mac_len, data, count);
         state->mac_len += count;