[PATCH] fixup! libfile: factor out zero-page resistant read_file as __read_full_anywhere
Ahmad Fatoum
a.fatoum at pengutronix.de
Tue Feb 24 03:01:07 PST 2026
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 at anthropic.com>
Signed-off-by: Ahmad Fatoum <a.fatoum at 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
More information about the barebox
mailing list