Linux-Integrity Archive on lore.kernel.org
 help / Atom feed
* [PATCH] ima-evm-utils: fix memory leak in ima_calc_hash
@ 2019-02-06 12:47 Vitaly Chikunov
  0 siblings, 0 replies; 1+ messages in thread
From: Vitaly Chikunov @ 2019-02-06 12:47 UTC (permalink / raw)
  To: Mimi Zohar, Dmitry Kasatkin, linux-integrity

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


^ permalink raw reply	[flat|nested] 1+ messages in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-06 12:47 [PATCH] ima-evm-utils: fix memory leak in ima_calc_hash Vitaly Chikunov

Linux-Integrity Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-integrity/0 linux-integrity/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-integrity linux-integrity/ https://lore.kernel.org/linux-integrity \
		linux-integrity@vger.kernel.org linux-integrity@archiver.kernel.org
	public-inbox-index linux-integrity


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-integrity


AGPL code for this site: git clone https://public-inbox.org/ public-inbox