File tree Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change 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+
3942apr_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 ;
46+ apr_interval_time_t raw_timeout ;
4347 int rc , timeout ;
4448
45- timeout = f ? f -> timeout : s -> timeout ;
49+ raw_timeout = f ? f -> timeout : s -> timeout ;
50+
51+ if (raw_timeout > ((apr_interval_time_t )INT_MAX ) * 1000 ) {
52+ /* timeout value exceeds maximum allowed (~25 days in microseconds)
53+ * capping to INT_MAX milliseconds to avoid overflow */
54+ timeout = INT_MAX ;
55+ } else {
56+ timeout = USEC_TO_MSEC (raw_timeout );
57+ }
58+
4659 pfd .fd = f ? f -> filedes : s -> socketdes ;
4760 pfd .events = for_read ? POLLIN : POLLOUT ;
4861
49- if (timeout > 0 ) {
50- timeout = (timeout + 999 ) / 1000 ;
51- }
5262 do {
5363 rc = poll (& pfd , 1 , timeout );
5464 } while (rc == -1 && errno == EINTR );
You can’t perform that action at this time.
0 commit comments