mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] uimage: use read_full where appropriate
@ 2024-10-02 16:36 Ahmad Fatoum
  2024-10-14 12:59 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2024-10-02 16:36 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

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




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] uimage: use read_full where appropriate
  2024-10-02 16:36 [PATCH] uimage: use read_full where appropriate Ahmad Fatoum
@ 2024-10-14 12:59 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2024-10-14 12:59 UTC (permalink / raw)
  To: barebox, Ahmad Fatoum


On Wed, 02 Oct 2024 18:36:21 +0200, Ahmad Fatoum wrote:
> 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.
> 
> [...]

Applied, thanks!

[1/1] uimage: use read_full where appropriate
      https://git.pengutronix.de/cgit/barebox/commit/?id=a77f55e34932 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-10-14 13:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-02 16:36 [PATCH] uimage: use read_full where appropriate Ahmad Fatoum
2024-10-14 12:59 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox