mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] fixup! libfile: factor out zero-page resistant read_file as __read_full_anywhere
@ 2026-02-24 11:01 Ahmad Fatoum
  0 siblings, 0 replies; only message in thread
From: Ahmad Fatoum @ 2026-02-24 11:01 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum, Claude Opus 4.6

libfile: fix error masking in __read_full_anywhere

When the second read_full() call fails with a negative error code,
the function returns now + error_code, which is a positive value
that looks like a successful short read. For example, 4096 + (-5)
returns 4091 instead of propagating the -EIO.

Check the return value of the second read_full separately.

Reported-by: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 lib/libfile.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/lib/libfile.c b/lib/libfile.c
index f6eeaebe4cd1..f5cea7b94998 100644
--- a/lib/libfile.c
+++ b/lib/libfile.c
@@ -807,7 +807,7 @@ int cache_file(const char *path, char **newpath)
  */
 int __read_full_anywhere(int fd, void *buf, size_t size)
 {
-	ssize_t now = 0;
+	ssize_t nbytes = 0, now;
 
 	if (unlikely(zero_page_contains((ulong)buf))) {
 		void *tmp = malloc(PAGE_SIZE);
@@ -822,9 +822,12 @@ int __read_full_anywhere(int fd, void *buf, size_t size)
 
 		if (now <= 0)
 			return now;
+
+		nbytes += now;
 	}
 
-	return now + read_full(fd, buf + now, size - now);
+	now = read_full(fd, buf + nbytes, size - nbytes);
+	return now < 0 ? now : now + nbytes;
 }
 
 #define BUFSIZ	(PAGE_SIZE * 32)
-- 
2.47.3




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-02-24 11:02 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-02-24 11:01 [PATCH] fixup! libfile: factor out zero-page resistant read_file as __read_full_anywhere Ahmad Fatoum

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