Skip to content

fix: prevent C errors when using weird max_execution_time values #13942

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Zend/zend_execute_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -1518,6 +1518,11 @@ static void zend_set_timeout_ex(zend_long seconds, bool reset_signals) /* {{{ */
struct itimerval t_r; /* timeout requested */
int signo;

// Prevent EINVAL error
if (seconds < 0 || seconds > 999999999) {
seconds = 0;
Copy link
Contributor

@staabm staabm Apr 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe raise a warning?

Copy link
Contributor

@withinboredom withinboredom Apr 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, other SAPI's don't appear to raise a warning and a lot of people make warnings exceptions. But yeah, I agree and that's the entire purpose of the discussion on internals....

For now, it is probably better to conform to existing behavior vs. introducing new behavior.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. On a second look, this is just making zend-max-execution-timers consistent with other timeout implementations. set_time_limit(-1) disables the timeout (probably by accident), and people rely on it: https://github.com/search?q=%22set_time_limit%28-1%29%22&type=code.

}

if(seconds) {
t_r.it_value.tv_sec = seconds;
t_r.it_value.tv_usec = t_r.it_interval.tv_sec = t_r.it_interval.tv_usec = 0;
Expand Down
5 changes: 5 additions & 0 deletions Zend/zend_max_execution_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ void zend_max_execution_timer_settime(zend_long seconds) /* {{{ }*/

timer_t timer = EG(max_execution_timer_timer);

// Prevent EINVAL error
if (seconds < 0 || seconds > 999999999) {
seconds = 0;
}

struct itimerspec its;
its.it_value.tv_sec = seconds;
its.it_value.tv_nsec = its.it_interval.tv_sec = its.it_interval.tv_nsec = 0;
Expand Down