mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Cc: Andrey Smirnov <andrew.smirnov@gmail.com>
Subject: [PATCH] crypto: digest: fix digesting file windows
Date: Thu,  9 May 2019 11:46:54 +0200	[thread overview]
Message-ID: <20190509094654.1874-1-s.hauer@pengutronix.de> (raw)

When digesting a file we always try toread PAGE_SIZE bytes. When we get a
short read because we reached the file end then the code works
correctly. If instead we only want to digest a part of the file then
we must make sure to only read up to 'size' bytes.

Fixes: b77582effd ("crypto: digest: Split memory vs. file code into separate functions")

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 crypto/digest.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/crypto/digest.c b/crypto/digest.c
index 2c4de2e4f1..360c261e40 100644
--- a/crypto/digest.c
+++ b/crypto/digest.c
@@ -233,17 +233,18 @@ static int digest_update_from_fd(struct digest *d, int fd,
 	}
 
 	while (size) {
-		const ssize_t now = read(fd, buf, PAGE_SIZE);
-		if (now < 0) {
-			ret = now;
+		unsigned long now = min_t(typeof(size), PAGE_SIZE, size);
+
+		ret = read(fd, buf, now);
+		if (ret < 0) {
 			perror("read");
 			goto out_free;
 		}
 
-		if (!now)
+		if (!ret)
 			break;
 
-		ret = digest_update_interruptible(d, buf, now);
+		ret = digest_update_interruptible(d, buf, ret);
 		if (ret)
 			goto out_free;
 
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

                 reply	other threads:[~2019-05-09  9:47 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=20190509094654.1874-1-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=andrew.smirnov@gmail.com \
    --cc=barebox@lists.infradead.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