Skip to content
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

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

Merged

Conversation

dunglas
Copy link
Contributor

@dunglas dunglas commented Apr 11, 2024

Calling set_time_limit() or setting max_execution_time to a negative value or to a value superior to 999,999,999 can trigger C errors: dunglas/frankenphp#713 / https://linux.die.net/man/2/setitimer

This patch normalizes such values as 0.

@withinboredom raised the issue on https://externals.io/message/123108, and we may indeed correctly specify this behavior, but in the meantime, we should at least not throw a C error, which is inconsistent with what is done on other platforms.

@dunglas dunglas changed the base branch from master to PHP-8.2 April 11, 2024 14:06
Copy link
Contributor

@withinboredom withinboredom left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -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.

@arnaud-lb arnaud-lb merged commit f6e8145 into php:PHP-8.2 Apr 16, 2024
9 of 10 checks passed
@arnaud-lb
Copy link
Member

Thank you!

arnaud-lb added a commit to arnaud-lb/php-src that referenced this pull request Apr 16, 2024
* PHP-8.2:
  [ci skip] NEWS
  fix: zend-max-execution-timers with negative or high timeout value (php#13942)
  Use return value of getpwuid_r(), not errno (php#13969)
arnaud-lb added a commit to arnaud-lb/php-src that referenced this pull request Apr 16, 2024
* PHP-8.3:
  [ci skip] NEWS
  [ci skip] NEWS
  fix: zend-max-execution-timers with negative or high timeout value (php#13942)
  Use return value of getpwuid_r(), not errno (php#13969)
@dragoonis
Copy link
Contributor

Nice find @dunglas

@dunglas dunglas deleted the fix/invalid-max_execution_time-values branch April 16, 2024 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants