svn commit: r1929253 - in apr/apr/branches/1.7.x: . support/unix
[email protected] Tue, 21 Oct 2025 15:40:05 -0000
| Newsgroups | gmane.comp.apache.apr.cvs |
|---|---|
| Message-ID | <176106120526.1279024.11457376156207343882@svn02-us-east.apache.org> |
Author: rpluem Date: Tue Oct 21 15:40:04 2025 New Revision: 1929253 Log: Merge r1929188 from trunk: * Avoid an overflow when converting the given INT64 timeout in microseconds to an INT32 timeout in milliseconds. PR: 69542 Obtained from: https://github.com/apache/apr/pull/62 Submitted by: [Alejandro Perez <[email protected]>] Reviewed by: rpluem Modified: apr/apr/branches/1.7.x/ (props changed) apr/apr/branches/1.7.x/CHANGES apr/apr/branches/1.7.x/support/unix/waitio.c Modified: apr/apr/branches/1.7.x/CHANGES ============================================================================== --- apr/apr/branches/1.7.x/CHANGES Tue Oct 21 15:32:51 2025 (r1929252) +++ apr/apr/branches/1.7.x/CHANGES Tue Oct 21 15:40:04 2025 (r1929253) @@ -1,6 +1,9 @@ -*- coding: utf-8 -*- Changes for APR 1.7.7 + *) apr_wait_for_io_or_timeout: Fix integer overflow for larger timeout values. + PR 69542 [Alejandro Perez <[email protected]>] + Changes for APR 1.7.6 *) test/testsock.c (test_get_addr): Fix test to portably switch Modified: apr/apr/branches/1.7.x/support/unix/waitio.c ============================================================================== --- apr/apr/branches/1.7.x/support/unix/waitio.c Tue Oct 21 15:32:51 2025 (r1929252) +++ apr/apr/branches/1.7.x/support/unix/waitio.c Tue Oct 21 15:40:04 2025 (r1929253) @@ -40,15 +40,22 @@ apr_status_t apr_wait_for_io_or_timeout( int for_read) { struct pollfd pfd; + apr_interval_time_t raw_timeout; int rc, timeout; - timeout = f ? f->timeout : s->timeout; + raw_timeout = f ? f->timeout : s->timeout; + if (raw_timeout > ((apr_interval_time_t)INT_MAX) * 1000) { + /* timeout value exceeds maximum allowed (~25 days in microseconds) + * capping to INT_MAX milliseconds to avoid overflow */ + timeout = INT_MAX; + } else { + /* convert microseconds to milliseconds (round up) */ + timeout = raw_timeout > 0 ? (int)((raw_timeout + 999) / 1000) : (int)raw_timeout; + } + pfd.fd = f ? f->filedes : s->socketdes; pfd.events = for_read ? POLLIN : POLLOUT; - if (timeout > 0) { - timeout = (timeout + 999) / 1000; - } do { rc = poll(&pfd, 1, timeout); } while (rc == -1 && errno == EINTR);