Skip to content

Commit d4440e9

Browse files
poetteringbluca
authored andcommitted
io-util: protect against INT_MAX overflow in flush_fd()
(cherry picked from commit 874c4be) (cherry picked from commit 93fc50ec2b3f505e20774dda45b37f1b594a4226) (cherry picked from commit a332cc7f6a444e8f738476c2cc12d93ef286cf24) (cherry picked from commit 57aaba3) (cherry picked from commit 9341836)
1 parent 7ccb1f6 commit d4440e9

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
@@ -23,27 +23,27 @@ int flush_fd(int fd) {
2323
int r;
2424

2525
r = fd_wait_for_event(fd, POLLIN, 0);
26-
if (r < 0) {
27-
if (r == -EINTR)
28-
continue;
29-
26+
if (r == -EINTR)
27+
continue;
28+
if (r < 0)
3029
return r;
31-
}
3230
if (r == 0)
3331
return count;
3432

3533
l = read(fd, buf, sizeof(buf));
3634
if (l < 0) {
3735
if (errno == EINTR)
3836
continue;
39-
4037
if (errno == EAGAIN)
4138
return count;
4239

4340
return -errno;
4441
} else if (l == 0)
4542
return count;
4643

44+
if (l > INT_MAX-count) /* On overflow terminate */
45+
return INT_MAX;
46+
4747
count += (int) l;
4848
}
4949
}

0 commit comments

Comments
 (0)