Thread (3 messages) 3 messages, 1 author, 2021-07-16
STALE1781d

[PATCH ima-evm-utils 2/3] Address "ignoring number of bytes read" messages

From: Mimi Zohar <zohar@linux.ibm.com>
Date: 2021-07-16 14:05:46
Subsystem: the rest · Maintainer: Linus Torvalds

Coverity complains about the existing "if (!fread(....))" and inverse
syntax.  Change it to make Coverity happy.

Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
---
 src/evmctl.c    | 4 ++--
 src/libimaevm.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/evmctl.c b/src/evmctl.c
index e1464ade4837..23be73d9bb97 100644
--- a/src/evmctl.c
+++ b/src/evmctl.c
@@ -2011,7 +2011,7 @@ static int ima_measurement(const char *file)
 		}
 	}
 
-	while (fread(&entry.header, sizeof(entry.header), 1, fp)) {
+	while (fread(&entry.header, sizeof(entry.header), 1, fp) == 1) {
 		entry_num++;
 		if (entry.header.pcr >= NUM_PCRS) {
 			log_err("Invalid PCR %d.\n", entry.header.pcr);
@@ -2233,7 +2233,7 @@ static int read_binary_bios_measurements(char *file, struct tpm_bank_info *bank)
 		log_info("Reading the TPM 1.2 event log %s.\n", file);
 
 	/* Extend the pseudo TPM PCRs with the event digest */
-	while (fread(&event, sizeof(event.header), 1, fp)) {
+	while (fread(&event, sizeof(event.header), 1, fp) == 1) {
 		if (imaevm_params.verbose > LOG_INFO) {
 			log_info("%02u ", event.header.pcr);
 			log_dump(event.header.digest, SHA_DIGEST_LENGTH);
diff --git a/src/libimaevm.c b/src/libimaevm.c
index 6591d20c7662..261712717368 100644
--- a/src/libimaevm.c
+++ b/src/libimaevm.c
@@ -156,7 +156,7 @@ static int add_file_hash(const char *file, EVP_MD_CTX *ctx)
 
 	for (size = stats.st_size; size; size -= len) {
 		len = MIN(size, bs);
-		if (!fread(data, len, 1, fp)) {
+		if (fread(data, len, 1, fp) != 1) {
 			if (ferror(fp)) {
 				log_err("fread() failed\n\n");
 				goto out;
-- 
2.27.0
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help