linux-integrity.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Fix file2bin fread return value checking
@ 2020-01-25 10:01 Patrick Uiterwijk
  0 siblings, 0 replies; only message in thread
From: Patrick Uiterwijk @ 2020-01-25 10:01 UTC (permalink / raw)
  To: linux-integrity; +Cc: Patrick Uiterwijk

The fread(3) function only returns the number of bytes read if size=1.
Instead, this function is used with the file length as size, and nmemb=1,
in which case it returns the number of elements read, not their length.
So it will return "1" if at least size bytes were read, so we should be
expecting that.

Signed-off-by: Patrick Uiterwijk <patrick@puiterwijk.org>
---
 src/evmctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/evmctl.c b/src/evmctl.c
index b02be8b..5a5afc5 100644
--- a/src/evmctl.c
+++ b/src/evmctl.c
@@ -205,7 +205,7 @@ static unsigned char *file2bin(const char *file,
const char *ext, int *size)
 		fclose(fp);
 		return NULL;
 	}
-	if (fread(data, len, 1, fp) != len) {
+	if (fread(data, len, 1, fp) != 1) {
 		log_err("Failed to fread %zu bytes: %s\n", len, name);
 		fclose(fp);
 		free(data);
-- 
2.24.1

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2020-01-25 10:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-25 10:01 [PATCH] Fix file2bin fread return value checking Patrick Uiterwijk

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).