]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
io-util: protect against INT_MAX overflow in flush_fd()
authorLennart Poettering <lennart@poettering.net>
Wed, 4 Jun 2025 14:05:41 +0000 (16:05 +0200)
committerMike Yuan <me@yhndnzj.com>
Wed, 4 Jun 2025 20:06:52 +0000 (22:06 +0200)
src/basic/io-util.c

index 82fad1303f95cc3f3d90daffd350c39307e7dd24..0b54464cc404d214d5478f91c48fe383ca0c890f 100644 (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;
         }
 }