diff mbox series

[1/6] libimaevm: Properly check for error returned by EVP_DigestUpdate

Message ID 20210419150151.236409-2-stefanb@linux.ibm.com (mailing list archive)
State New, archived
Headers show
Series ima-evm-utils: Some cleanups and bugfixes | expand

Commit Message

Stefan Berger April 19, 2021, 3:01 p.m. UTC
The error checking in add_dir_hash was wrong. EVP_DigestUpdate returns 1
on success and 0 on error, so we cannot just accumulate it using or'ing.

From the man page:
       EVP_DigestInit_ex(), EVP_DigestUpdate(), EVP_DigestFinal_ex()
           Returns 1 for success and 0 for failure.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
---
 src/libimaevm.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/src/libimaevm.c b/src/libimaevm.c
index fa6c278..d8fc0d4 100644
--- a/src/libimaevm.c
+++ b/src/libimaevm.c
@@ -179,7 +179,6 @@  out:
 
 static int add_dir_hash(const char *file, EVP_MD_CTX *ctx)
 {
-	int err;
 	struct dirent *de;
 	DIR *dir;
 	unsigned long long ino, off;
@@ -198,11 +197,10 @@  static int add_dir_hash(const char *file, EVP_MD_CTX *ctx)
 		type = de->d_type;
 		log_debug("entry: %s, ino: %llu, type: %u, off: %llu, reclen: %hu\n",
 			  de->d_name, ino, type, off, de->d_reclen);
-		err = EVP_DigestUpdate(ctx, de->d_name, strlen(de->d_name));
-		/*err |= EVP_DigestUpdate(ctx, &off, sizeof(off));*/
-		err |= EVP_DigestUpdate(ctx, &ino, sizeof(ino));
-		err |= EVP_DigestUpdate(ctx, &type, sizeof(type));
-		if (!err) {
+		if (EVP_DigestUpdate(ctx, de->d_name, strlen(de->d_name)) != 1 ||
+		    /* EVP_DigestUpdate(ctx, &off, sizeof(off)) != 1 || */
+		    EVP_DigestUpdate(ctx, &ino, sizeof(ino)) != 1||
+		    EVP_DigestUpdate(ctx, &type, sizeof(type)) != 1) {
 			log_err("EVP_DigestUpdate() failed\n");
 			output_openssl_errors();
 			result = 1;