svn commit: r1929188 - in apr/apr/trunk: . support/unix
[email protected] Fri, 17 Oct 2025 08:21:41 -0000
| Newsgroups | gmane.comp.apache.apr.cvs |
|---|---|
| Message-ID | <176068930145.2984217.9758795278216399069@svn02-us-east.apache.org> |
Author: rpluem Date: Fri Oct 17 08:21:41 2025 New Revision: 1929188 Log: * 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/trunk/CHANGES apr/apr/trunk/support/unix/waitio.c Modified: apr/apr/trunk/CHANGES ============================================================================== --- apr/apr/trunk/CHANGES Fri Oct 17 07:26:54 2025 (r1929187) +++ apr/apr/trunk/CHANGES Fri Oct 17 08:21:41 2025 (r1929188) @@ -1,6 +1,9 @@ -*- coding: utf-8 -*- Changes for APR 2.0.0 + *) apr_wait_for_io_or_timeout: Fix integer overflow for larger timeout values. + PR 69542 [Alejandro Perez <[email protected]>] + *) apr_strings: Add apr_strqtok() function to tokenise quoted strings. [Graham Leggett] Modified: apr/apr/trunk/support/unix/waitio.c ============================================================================== --- apr/apr/trunk/support/unix/waitio.c Fri Oct 17 07:26:54 2025 (r1929187) +++ apr/apr/trunk/support/unix/waitio.c Fri Oct 17 08:21:41 2025 (r1929188) @@ -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);