Skip to content

Commit 38ea886

Browse files
author
Alejandro Perez Pestana
committed
waitio: Fix timeout integer overflow
Fix integer overflow in apr_wait_for_io_or_timeout by performing the microseconds to milliseconds conversion before assigning to 32-bit timeout.
1 parent d6bb3f9 commit 38ea886

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

support/unix/waitio.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,19 @@
3636
#include <sys/poll.h>
3737
#endif
3838

39+
/* convert microseconds to milliseconds (round up) */
40+
#define USEC_TO_MSEC(t) ((t) > 0 ? ((t) + 999) / 1000 : (t))
41+
3942
apr_status_t apr_wait_for_io_or_timeout(apr_file_t *f, apr_socket_t *s,
4043
int for_read)
4144
{
4245
struct pollfd pfd;
4346
int rc, timeout;
4447

45-
timeout = f ? f->timeout : s->timeout;
46-
pfd.fd = f ? f->filedes : s->socketdes;
47-
pfd.events = for_read ? POLLIN : POLLOUT;
48+
timeout = f ? USEC_TO_MSEC(f->timeout) : USEC_TO_MSEC(s->timeout);
49+
pfd.fd = f ? f->filedes : s->socketdes;
50+
pfd.events = for_read ? POLLIN : POLLOUT;
4851

49-
if (timeout > 0) {
50-
timeout = (timeout + 999) / 1000;
51-
}
5252
do {
5353
rc = poll(&pfd, 1, timeout);
5454
} while (rc == -1 && errno == EINTR);

0 commit comments

Comments
 (0)