diff --git a/main/channel.c b/main/channel.c index bd157acfa5..6073bf91c7 100644 --- a/main/channel.c +++ b/main/channel.c @@ -2068,10 +2068,15 @@ struct ast_channel *ast_waitfor_nandfds(struct ast_channel **c, int n, int *fds, } /* Wait full interval */ rms = *ms; - if (!ast_tvzero(whentohangup)) { + /* INT_MAX, not LONG_MAX, because it matters on 64-bit */ + if (!ast_tvzero(whentohangup) && whentohangup.tv_sec < INT_MAX / 1000) { rms = whentohangup.tv_sec * 1000 + whentohangup.tv_usec / 1000; /* timeout in milliseconds */ - if (*ms >= 0 && *ms < rms) /* original *ms still smaller */ + if (*ms >= 0 && *ms < rms) { /* original *ms still smaller */ rms = *ms; + } + } else if (!ast_tvzero(whentohangup) && rms < 0) { + /* Tiny corner case... call would need to last >24 days */ + rms = INT_MAX; } /* * Build the pollfd array, putting the channels' fds first,