public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fixdep: handle short reads in read_file
@ 2024-09-06 15:29 Sam James
  2024-09-07  2:02 ` Masahiro Yamada
  0 siblings, 1 reply; 6+ messages in thread
From: Sam James @ 2024-09-06 15:29 UTC (permalink / raw)
  To: Masahiro Yamada, Nathan Chancellor, Nicolas Schier
  Cc: Sam James, Masahiro Yamada, linux-kbuild, linux-kernel

50% or so of kernel builds within our package manager fail for me with
'fixdep: read: success' because read(), for some reason - possibly ptrace,
only read a short amount, not the full size.

Unfortunately, this didn't trigger a -Wunused-result warning because
we _are_ checking the return value, but with a bad comparison (it's completely
fine for read() to not read the whole file in one gulp).

Fixes: 01b5cbe7012fb1eeffc5c143865569835bcd405e
Signed-off-by: Sam James <sam@gentoo.org>
---
 scripts/basic/fixdep.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
index 84b6efa849f4d..04d7742c99ac2 100644
--- a/scripts/basic/fixdep.c
+++ b/scripts/basic/fixdep.c
@@ -233,9 +233,15 @@ static void *read_file(const char *filename)
 		perror("fixdep: malloc");
 		exit(2);
 	}
-	if (read(fd, buf, st.st_size) != st.st_size) {
-		perror("fixdep: read");
-		exit(2);
+	ssize_t bytes = 0;
+	while (bytes < st.st_size) {
+               ssize_t cur = read(fd, buf + bytes, st.st_size - bytes);
+		if (cur == -1) {
+			perror("fixdep: read");
+			exit(2);
+		} else {
+			bytes += cur;
+		}
 	}
 	buf[st.st_size] = '\0';
 	close(fd);
-- 
2.46.0


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

end of thread, other threads:[~2024-09-08  8:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-06 15:29 [PATCH] fixdep: handle short reads in read_file Sam James
2024-09-07  2:02 ` Masahiro Yamada
2024-09-07 10:14   ` Sam James
2024-09-07 13:26     ` Sam James
2024-09-07 23:48       ` Masahiro Yamada
2024-09-08  8:20         ` Sam James

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