From 874c4beb24ade904589bf672685752727cbb791e Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 4 Jun 2025 16:05:41 +0200 Subject: [PATCH] io-util: protect against INT_MAX overflow in flush_fd() --- src/basic/io-util.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/basic/io-util.c b/src/basic/io-util.c index 82fad1303f9..0b54464cc40 100644 --- a/src/basic/io-util.c +++ b/src/basic/io-util.c @@ -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; } } -- 2.47.3