mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH] uimage: use read_full where appropriate
Date: Wed,  2 Oct 2024 18:36:21 +0200	[thread overview]
Message-ID: <20241002163621.2458659-1-a.fatoum@pengutronix.de> (raw)

Apart from the CRC code, where it's no problem to just compute the CRC
of the last read and read again, all other instances of read() in the
uimage code are written with the assumption that the read will not be
short.

Use read_full to satisfy this assumption.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/uimage.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/common/uimage.c b/common/uimage.c
index c578edae2606..06a2c05ead67 100644
--- a/common/uimage.c
+++ b/common/uimage.c
@@ -110,7 +110,7 @@ struct uimage_handle *uimage_open(const char *filename)
 
 	handle->copy = copy;
 
-	if (read(fd, header, sizeof(*header)) < 0) {
+	if (read_full(fd, header, sizeof(*header)) != sizeof(*header)) {
 		printf("could not read: %m\n");
 		goto err_out;
 	}
@@ -150,8 +150,8 @@ struct uimage_handle *uimage_open(const char *filename)
 		for (i = 0; i < MAX_MULTI_IMAGE_COUNT; i++) {
 			u32 size;
 
-			ret = read(fd, &size, sizeof(size));
-			if (ret < 0)
+			ret = read_full(fd, &size, sizeof(size));
+			if (ret != sizeof(size))
 				goto err_out;
 
 			if (!size)
@@ -437,8 +437,8 @@ void *uimage_load_to_buf(struct uimage_handle *handle, int image_no,
 		goto out;
 	}
 
-	ret = read(handle->fd, ftbuf, 128);
-	if (ret < 0)
+	ret = read_full(handle->fd, ftbuf, 128);
+	if (ret != 128)
 		return NULL;
 
 	ft = file_detect_type(ftbuf, 128);
@@ -452,8 +452,8 @@ void *uimage_load_to_buf(struct uimage_handle *handle, int image_no,
 	if (lseek(handle->fd, off, SEEK_SET) != off)
 		return NULL;
 
-	ret = read(handle->fd, &size, 4);
-	if (ret < 0)
+	ret = read_full(handle->fd, &size, 4);
+	if (ret != 4)
 		return NULL;
 
 	size = le32_to_cpu(size);
-- 
2.39.5




             reply	other threads:[~2024-10-02 16:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-02 16:36 Ahmad Fatoum [this message]
2024-10-14 12:59 ` Sascha Hauer

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=20241002163621.2458659-1-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --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