[php-src] PHP-8.5: Merge branch 'PHP-8.4' into PHP-8.5
| From: | David Carlier | Date: | Sat, 26 Sep 2026 17:26:55 +0000 |
| Subject: | [php-src] PHP-8.5: Merge branch 'PHP-8.4' into PHP-8.5 | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-141583@lists.php.net to get a copy of this message | ||
Author: David Carlier (devnexen)
Date: 2026-09-26T18:25:39+01:00
Commit: https://github.com/php/php-src/commit/85703b71ba8be66628831cebf0a4b9887b22ade5
Raw diff: https://github.com/php/php-src/commit/85703b71ba8be66628831cebf0a4b9887b22ade5.diff
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
ext/pcntl: fix an off by one bound and a parameter the parser made required
Changed paths:
A ext/pcntl/tests/pcntl_cpuaffinity_bound.phpt
M ext/pcntl/pcntl.c
M ext/pcntl/tests/pcntl_qosclass.phpt
Diff:
diff --git a/ext/pcntl/pcntl.c b/ext/pcntl/pcntl.c
index 52beffd1c6e2..912e13ac48a7 100644
--- a/ext/pcntl/pcntl.c
+++ b/ext/pcntl/pcntl.c
@@ -1839,7 +1839,7 @@ PHP_FUNCTION(pcntl_setcpuaffinity)
}
if (cpu < 0 || cpu >= maxcpus) {
- zend_argument_value_error(2, "cpu id must be between 0 and " ZEND_ULONG_FMT "
(" ZEND_LONG_FMT ")", maxcpus, cpu);
+ zend_argument_value_error(2, "cpu id must be between 0 and " ZEND_LONG_FMT "
(" ZEND_LONG_FMT ")", maxcpus - 1, cpu);
PCNTL_CPU_DESTROY(mask);
RETURN_THROWS();
}
@@ -1946,13 +1946,14 @@ PHP_FUNCTION(pcntl_getqos_class)
PHP_FUNCTION(pcntl_setqos_class)
{
- zval *qos_obj;
+ zval *qos_obj = NULL;
- ZEND_PARSE_PARAMETERS_START(1, 1)
+ ZEND_PARSE_PARAMETERS_START(0, 1)
+ Z_PARAM_OPTIONAL
Z_PARAM_OBJECT_OF_CLASS(qos_obj, QosClass_ce)
ZEND_PARSE_PARAMETERS_END();
- qos_class_t qos_class = qos_zval_to_lval(qos_obj);
+ qos_class_t qos_class = qos_obj ? qos_zval_to_lval(qos_obj) : QOS_CLASS_DEFAULT;
if (UNEXPECTED(pthread_set_qos_class_self_np((qos_class_t)qos_class, 0) != 0))
{
diff --git a/ext/pcntl/tests/pcntl_cpuaffinity_bound.phpt
b/ext/pcntl/tests/pcntl_cpuaffinity_bound.phpt
new file mode 100644
index 000000000000..6b415a52c242
--- /dev/null
+++ b/ext/pcntl/tests/pcntl_cpuaffinity_bound.phpt
@@ -0,0 +1,52 @@
+--TEST--
+pcntl_setcpuaffinity(): the upper bound the error advertises is itself a valid cpu id
+--EXTENSIONS--
+pcntl
+--SKIPIF--
+<?php
+if (PHP_OS_FAMILY === 'Solaris') {
+ die("skip broken pset_create()");
+}
+if (!function_exists("pcntl_setcpuaffinity")) die("skip pcntl_setcpuaffinity is not
available");
+?>
+--FILE--
+<?php
+$pid = getmypid();
+$prefix = 'pcntl_setcpuaffinity(): Argument #2 ($cpu_ids) cpu id must be between 0 and ';
+
+/* read the advertised bound out of the message itself */
+try {
+ pcntl_setcpuaffinity($pid, [PHP_INT_MAX]);
+ exit("PHP_INT_MAX was accepted as a cpu id" . PHP_EOL);
+} catch (Throwable $e) {
+ echo $e::class, "\n";
+ if (!preg_match('/must be between 0 and (\d+) \(/', $e->getMessage(), $m)) {
+ exit("unexpected message: " . $e->getMessage() . PHP_EOL);
+ }
+}
+$bound = (int) $m[1];
+
+/* Every id is range checked before any syscall runs, so pairing the advertised
+ bound with an out of range id shows which of the two the check rejects,
+ without ever changing the process affinity. */
+try {
+ pcntl_setcpuaffinity($pid, [$bound, PHP_INT_MAX]);
+} catch (Throwable $e) {
+ echo $e::class, "\n";
+ var_dump($e->getMessage() === $prefix . $bound . ' (' . PHP_INT_MAX .
')');
+}
+
+/* and the first id past the bound is rejected, naming itself */
+try {
+ pcntl_setcpuaffinity($pid, [$bound + 1]);
+} catch (Throwable $e) {
+ echo $e::class, "\n";
+ var_dump($e->getMessage() === $prefix . $bound . ' (' . ($bound + 1) .
')');
+}
+?>
+--EXPECT--
+ValueError
+ValueError
+bool(true)
+ValueError
+bool(true)
diff --git a/ext/pcntl/tests/pcntl_qosclass.phpt b/ext/pcntl/tests/pcntl_qosclass.phpt
index f8ca1a706bd2..947afdb4836b 100644
--- a/ext/pcntl/tests/pcntl_qosclass.phpt
+++ b/ext/pcntl/tests/pcntl_qosclass.phpt
@@ -13,7 +13,12 @@ pcntl_setqos_class(Pcntl\QosClass::Default);
var_dump(Pcntl\QosClass::Default === pcntl_getqos_class());
pcntl_setqos_class(Pcntl\QosClass::Background);
var_dump(Pcntl\QosClass::Background == pcntl_getqos_class());
+
+/* the parameter is optional, and omitting it applies the declared default */
+pcntl_setqos_class();
+var_dump(Pcntl\QosClass::Default === pcntl_getqos_class());
?>
--EXPECT--
bool(true)
bool(true)
+bool(true)