Skip to content

Commit 57aaba3

Browse files
poetteringbluca
authored andcommitted
io-util: protect against INT_MAX overflow in flush_fd()
(cherry picked from commit 874c4beb24ade904589bf672685752727cbb791e) (cherry picked from commit 93fc50ec2b3f505e20774dda45b37f1b594a4226) (cherry picked from commit a332cc7f6a444e8f738476c2cc12d93ef286cf24)
1 parent 18eda2f commit 57aaba3

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/basic/io-util.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,27 @@ int flush_fd(int fd) {
2525
int r;
2626

2727
r = fd_wait_for_event(fd, POLLIN, 0);
28-
if (r < 0) {
29-
if (r == -EINTR)
30-
continue;
31-
28+
if (r == -EINTR)
29+
continue;
30+
if (r < 0)
3231
return r;
33-
}
3432
if (r == 0)
3533
return count;
3634

3735
l = read(fd, buf, sizeof(buf));
3836
if (l < 0) {
3937
if (errno == EINTR)
4038
continue;
41-
4239
if (errno == EAGAIN)
4340
return count;
4441

4542
return -errno;
4643
} else if (l == 0)
4744
return count;
4845

46+
if (l > INT_MAX-count) /* On overflow terminate */
47+
return INT_MAX;
48+
4949
count += (int) l;
5050
}
5151
}

0 commit comments

Comments
 (0)