diff mbox series

Fix file2bin fread return value checking

Message ID CAJweMdZ62LkuRzA1BCupFJvDMEGsKJD4BSMmGJ0E85vWuPsPng@mail.gmail.com (mailing list archive)
State New, archived
Headers show
Series Fix file2bin fread return value checking | expand

Commit Message

Patrick Uiterwijk Jan. 25, 2020, 10:01 a.m. UTC
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(-)

 		free(data);
diff mbox series

Patch

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