io-util: protect against INT_MAX overflow in flush_fd()

This commit is contained in:
Lennart Poettering
2025-06-04 22:06:52 +02:00
committed by Mike Yuan
parent 46ab6b63e5
commit 874c4beb24
+6 -6
View File
@@ -24,12 +24,10 @@ int flush_fd(int fd) {
int r;
r = fd_wait_for_event(fd, POLLIN, 0);
if (r < 0) {
if (r == -EINTR)
continue;
if (r == -EINTR)
continue;
if (r < 0)
return r;
}
if (r == 0)
return count;
@@ -37,7 +35,6 @@ int flush_fd(int fd) {
if (l < 0) {
if (errno == EINTR)
continue;
if (errno == EAGAIN)
return count;
@@ -45,6 +42,9 @@ int flush_fd(int fd) {
} else if (l == 0)
return count;
if (l > INT_MAX-count) /* On overflow terminate */
return INT_MAX;
count += (int) l;
}
}