diff --git a/NEWS b/NEWS index 098f8b884f3..0c52b19d996 100644 --- a/NEWS +++ b/NEWS @@ -37,6 +37,9 @@ PHP NEWS - POSIX: . posix_kill and posix_setpgid throws a ValueError on invalid process_id. (David Carlier) + . posix_setpgid throws a ValueError on invalid process_group_id, + posix_setrlimit throws a ValueError on invalid soft_limit and hard_limit + arguments. (David Carlier) - Reflection: . Fixed bug GH-19187 (ReflectionNamedType::getName() prints nullable type when diff --git a/UPGRADING b/UPGRADING index 381fec6ba2e..e21eda5439a 100644 --- a/UPGRADING +++ b/UPGRADING @@ -384,8 +384,11 @@ PHP 8.5 UPGRADE NOTES last_error to EBADF and raises an E_WARNING message. . posix_kill throws a ValueError when the process_id argument is lower or greater than what supports the platform (signed integer or long - range), posix_setpgid throws a ValueError when the process_id is - lower than zero or greater than what supports the platform. + range), posix_setpgid throws a ValueError when the process_id or + the process_group_id is lower than zero or greater than + what supports the platform. + . posix_setrlimit throws a ValueError when the hard_limit of soft_limit + argument are lower than -1 or if soft_limit is greater than hard_limit. - Reflection: . The output of ReflectionClass::toString() for enums has changed to diff --git a/ext/posix/posix.c b/ext/posix/posix.c index a418a653386..ff878b3acfc 100644 --- a/ext/posix/posix.c +++ b/ext/posix/posix.c @@ -126,9 +126,9 @@ ZEND_GET_MODULE(posix) } \ RETURN_TRUE; -#define PHP_POSIX_CHECK_PID(pid, lower, upper) \ +#define PHP_POSIX_CHECK_PID(pid, arg, lower, upper) \ if (pid < lower || pid > upper) { \ - zend_argument_value_error(1, "must be between " ZEND_LONG_FMT " and " ZEND_LONG_FMT, lower, upper); \ + zend_argument_value_error(arg, "must be between " ZEND_LONG_FMT " and " ZEND_LONG_FMT, lower, upper); \ RETURN_THROWS(); \ } @@ -143,7 +143,7 @@ PHP_FUNCTION(posix_kill) Z_PARAM_LONG(sig) ZEND_PARSE_PARAMETERS_END(); - PHP_POSIX_CHECK_PID(pid, POSIX_PID_MIN, POSIX_PID_MAX) + PHP_POSIX_CHECK_PID(pid, 1, POSIX_PID_MIN, POSIX_PID_MAX) if (kill(pid, sig) < 0) { POSIX_G(last_error) = errno; @@ -307,7 +307,8 @@ PHP_FUNCTION(posix_setpgid) Z_PARAM_LONG(pgid) ZEND_PARSE_PARAMETERS_END(); - PHP_POSIX_CHECK_PID(pid, 0, POSIX_PID_MAX) + PHP_POSIX_CHECK_PID(pid, 1, 0, POSIX_PID_MAX) + PHP_POSIX_CHECK_PID(pgid, 2, 0, POSIX_PID_MAX) if (setpgid(pid, pgid) < 0) { POSIX_G(last_error) = errno; @@ -347,6 +348,8 @@ PHP_FUNCTION(posix_getsid) Z_PARAM_LONG(val) ZEND_PARSE_PARAMETERS_END(); + PHP_POSIX_CHECK_PID(val, 1, 0, POSIX_PID_MAX) + if ((val = getsid(val)) < 0) { POSIX_G(last_error) = errno; RETURN_FALSE; @@ -1201,6 +1204,21 @@ PHP_FUNCTION(posix_setrlimit) Z_PARAM_LONG(max) ZEND_PARSE_PARAMETERS_END(); + if (cur < -1) { + zend_argument_value_error(2, "must be greater or equal to -1"); + RETURN_THROWS(); + } + + if (max < -1) { + zend_argument_value_error(3, "must be greater or equal to -1"); + RETURN_THROWS(); + } + + if (max > -1 && cur > max) { + zend_argument_value_error(2, "must be lower or equal to " ZEND_LONG_FMT, max); + RETURN_THROWS(); + } + rl.rlim_cur = cur; rl.rlim_max = max; diff --git a/ext/posix/tests/posix_getsid_error.phpt b/ext/posix/tests/posix_getsid_error.phpt index c62eca58a84..68f16855499 100644 --- a/ext/posix/tests/posix_getsid_error.phpt +++ b/ext/posix/tests/posix_getsid_error.phpt @@ -9,7 +9,11 @@ PHP Testfest Berlin 2009-05-10 posix --FILE-- getMessage(), PHP_EOL; +} ?> ---EXPECT-- -bool(false) +--EXPECTF-- +posix_getsid(): Argument #1 ($process_id) must be between 0 and %d diff --git a/ext/posix/tests/posix_setpgid_error.phpt b/ext/posix/tests/posix_setpgid_error.phpt index 89cc45306e1..0d00dd87c60 100644 --- a/ext/posix/tests/posix_setpgid_error.phpt +++ b/ext/posix/tests/posix_setpgid_error.phpt @@ -16,7 +16,19 @@ try { } catch (\ValueError $e) { echo $e->getMessage(), PHP_EOL; } +try { + posix_setpgid(1, PHP_INT_MAX); +} catch (\ValueError $e) { + echo $e->getMessage(), PHP_EOL; +} +try { + posix_setpgid(1, -2); +} catch (\ValueError $e) { + echo $e->getMessage(), PHP_EOL; +} ?> --EXPECTF-- posix_setpgid(): Argument #1 ($process_id) must be between 0 and %d posix_setpgid(): Argument #1 ($process_id) must be between 0 and %d +posix_setpgid(): Argument #2 ($process_group_id) must be between 0 and %d +posix_setpgid(): Argument #2 ($process_group_id) must be between 0 and %d diff --git a/ext/posix/tests/posix_setrlimit.phpt b/ext/posix/tests/posix_setrlimit.phpt index cc8fadafc04..51638793f9d 100644 --- a/ext/posix/tests/posix_setrlimit.phpt +++ b/ext/posix/tests/posix_setrlimit.phpt @@ -12,9 +12,25 @@ if (str_contains(PHP_OS, 'FreeBSD')) die('skip different behavior on FreeBSD'); getMessage(), PHP_EOL; +} +try { + posix_setrlimit(POSIX_RLIMIT_NOFILE, -2, -1); +} catch (\ValueError $e) { + echo $e->getMessage(), PHP_EOL; +} +try { + posix_setrlimit(POSIX_RLIMIT_NOFILE, -1, -2); +} catch (\ValueError $e) { + echo $e->getMessage(), PHP_EOL; +} ?> --EXPECT-- bool(true) -bool(false) +posix_setrlimit(): Argument #2 ($soft_limit) must be lower or equal to 128 +posix_setrlimit(): Argument #2 ($soft_limit) must be greater or equal to -1 +posix_setrlimit(): Argument #3 ($hard_limit) must be greater or equal to -1