[PATCH] fixdep: handle short reads in read_file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 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





[Index of Archives]     [Linux&nblp;USB Development]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Yosemite Secrets]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux