linux-integrity.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vitaly Chikunov <vt@altlinux.org>
To: Mimi Zohar <zohar@linux.vnet.ibm.com>,
	Dmitry Kasatkin <dmitry.kasatkin@gmail.com>,
	linux-integrity@vger.kernel.org
Subject: [PATCH] ima-evm-utils: fix memory leak in ima_calc_hash
Date: Wed,  6 Feb 2019 15:47:27 +0300	[thread overview]
Message-ID: <20190206124727.2207-1-vt@altlinux.org> (raw)

Free EVP_MD_CTX in ima_calc_hash(). Also, remove legacy EVP_MD_CTX usage.

Signed-off-by: Vitaly Chikunov <vt@altlinux.org>
---
 src/libimaevm.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/src/libimaevm.c b/src/libimaevm.c
index 6070614..dccb74c 100644
--- a/src/libimaevm.c
+++ b/src/libimaevm.c
@@ -322,12 +322,6 @@ int ima_calc_hash(const char *file, uint8_t *hash)
 	EVP_MD_CTX *pctx;
 	unsigned int mdlen;
 	int err;
-#if OPENSSL_VERSION_NUMBER < 0x10100000
-	EVP_MD_CTX ctx;
-	pctx = &ctx;
-#else
-	pctx = EVP_MD_CTX_new();
-#endif
 
 	/*  Need to know the file length */
 	err = lstat(file, &st);
@@ -342,9 +336,11 @@ int ima_calc_hash(const char *file, uint8_t *hash)
 		return 1;
 	}
 
+	pctx = EVP_MD_CTX_new();
 	err = EVP_DigestInit(pctx, md);
 	if (!err) {
 		log_err("EVP_DigestInit() failed\n");
+		EVP_MD_CTX_free(pctx);
 		return 1;
 	}
 
@@ -364,18 +360,21 @@ int ima_calc_hash(const char *file, uint8_t *hash)
 		break;
 	default:
 		log_errno("Unsupported file type");
+		EVP_MD_CTX_free(pctx);
 		return -1;
 	}
 
-	if (err)
+	if (err) {
+		EVP_MD_CTX_free(pctx);
 		return err;
+	}
 
 	err = EVP_DigestFinal(pctx, hash, &mdlen);
+	EVP_MD_CTX_free(pctx);
 	if (!err) {
 		log_err("EVP_DigestFinal() failed\n");
 		return 1;
 	}
-
 	return mdlen;
 }
 
-- 
2.11.0


                 reply	other threads:[~2019-02-06 12:47 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190206124727.2207-1-vt@altlinux.org \
    --to=vt@altlinux.org \
    --cc=dmitry.kasatkin@gmail.com \
    --cc=linux-integrity@vger.kernel.org \
    --cc=zohar@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).