Skip to content

ext/pcntl: fix an off by one bound and a parameter the parser made required - #23553

Open
lacatoire wants to merge 1 commit into
php:masterfrom
lacatoire:fix/pcntl-qos-and-cpu-bound-upstream
Open

ext/pcntl: fix an off by one bound and a parameter the parser made required#23553
lacatoire wants to merge 1 commit into
php:masterfrom
lacatoire:fix/pcntl-qos-and-cpu-bound-upstream

Conversation

@lacatoire

Copy link
Copy Markdown
Member

Two unrelated slips in ext/pcntl/pcntl.c, together because they touch the same file.

pcntl_setcpuaffinity() rejects cpu >= maxcpus but advertises maxcpus as the inclusive upper bound, so on a 16-CPU host id 16 is refused by a message saying "between 0 and 16". It now prints maxcpus - 1. The same line printed maxcpus, a zend_long, with ZEND_ULONG_FMT; corrected to ZEND_LONG_FMT, since sysconf() can return -1.

pcntl_setqos_class() declares $qos_class optional with a default of Pcntl\QosClass::Default, but its ZPP block was (1, 1) and qos was left uninitialised, so calling it with no argument raised an ArgumentCountError and the declared default was unreachable. It now parses (0, 1) with Z_PARAM_OPTIONAL and initialises qos beforehand, as bcround() does for its optional enum parameter. This half is macOS-only and could not be exercised here.

The new test reads the bound out of the message rather than hardcoding a cpu count, then checks that the advertised bound is accepted and the next id refused; it fails on the current code. Master only, as the exception message changes.

Comment thread ext/pcntl/tests/pcntl_cpuaffinity_bound.phpt
…quired

pcntl_setcpuaffinity() refuses a cpu id equal to the cpu count but named
that count as the inclusive upper bound, printing a zend_long with the
unsigned format on the way. pcntl_setqos_class() declares $qos_class
optional while its parser demanded it, leaving the declared default
unreachable.
@lacatoire
lacatoire force-pushed the fix/pcntl-qos-and-cpu-bound-upstream branch from ad27950 to 6420da4 Compare September 4, 2026 06:43
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.

2 participants