Skip to content

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

Merged
arnaud-lb merged 1 commit into
php:PHP-8.2from
dunglas:fix/invalid-max_execution_time-values
Apr 16, 2024
Merged

fix: prevent C errors when using weird max_execution_time values#13942
arnaud-lb merged 1 commit into
php:PHP-8.2from
dunglas:fix/invalid-max_execution_time-values

Conversation

@dunglas

@dunglas dunglas commented Apr 11, 2024

Copy link
Copy Markdown
Member

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: php/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

@withinboredom withinboredom left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

Comment thread Zend/zend_execute_API.c

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

@staabm staabm Apr 11, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

maybe raise a warning?

@withinboredom withinboredom Apr 11, 2024

Copy link
Copy Markdown
Member

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
Copy Markdown
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
@arnaud-lb

Copy link
Copy Markdown
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
Copy Markdown
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