linux-integrity.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Patrick Uiterwijk <patrick@puiterwijk.org>
To: linux-integrity@vger.kernel.org
Cc: Patrick Uiterwijk <patrick@puiterwijk.org>
Subject: [PATCH] Fix file2bin fread return value checking
Date: Sat, 25 Jan 2020 02:01:46 -0800	[thread overview]
Message-ID: <CAJweMdZ62LkuRzA1BCupFJvDMEGsKJD4BSMmGJ0E85vWuPsPng@mail.gmail.com> (raw)

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

                 reply	other threads:[~2020-01-25 10:01 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAJweMdZ62LkuRzA1BCupFJvDMEGsKJD4BSMmGJ0E85vWuPsPng@mail.gmail.com \
    --to=patrick@puiterwijk.org \
    --cc=linux-integrity@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).