From 25aaea7e5d84b8717f804453572670880944bb24 Mon Sep 17 00:00:00 2001 From: Jorg Sowa Date: Fri, 16 Oct 2026 20:49:45 +0200 Subject: [PATCH] Fix posix_setrlimit() rejecting POSIX_RLIMIT_INFINITY on Solaris GH-19281 made posix_setrlimit() throw a ValueError for limits below -1, on the assumption that -1 (RLIM_INFINITY on Linux) is the only valid negative value. Solaris defines RLIM_INFINITY as (rlim_t)-3, so the function now rejects PHP's own POSIX_RLIMIT_INFINITY constant: ValueError: posix_setrlimit(): Argument #3 ($hard_limit) must be greater or equal to -1 On Solaris, also accept RLIM_INFINITY. Other platforms keep the existing check. This fixes ext/session/tests/session_write_failure_keeps_data.phpt in the nightly SOLARIS job. See https://docs.oracle.com/cd/E88353_01/html/E37841/setrlimit-2.html and https://github.com/illumos/illumos-gate/blob/master/usr/src/uts/common/sys/resource.h --- NEWS | 4 ++++ ext/posix/posix.c | 14 ++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/NEWS b/NEWS index 4b737751b074..94ec1e8ecfa0 100644 --- a/NEWS +++ b/NEWS @@ -72,6 +72,10 @@ PHP NEWS - Phpdbg: . Fix wrong command names. (ndossche, Weilin Du) +- POSIX: + . Fixed posix_setrlimit() rejecting POSIX_RLIMIT_INFINITY on Solaris. + (Jorg Sowa) + - Readline: . Fixed a crash in readline_info() when completion_append_character contains a non-ASCII byte. (Weilin Du) diff --git a/ext/posix/posix.c b/ext/posix/posix.c index e4c2b91678e9..b8d2e5a21a27 100644 --- a/ext/posix/posix.c +++ b/ext/posix/posix.c @@ -1217,7 +1217,14 @@ PHP_FUNCTION(posix_getrlimit) #endif /* HAVE_GETRLIMIT */ #ifdef HAVE_SETRLIMIT -/* {{{ Set system resource consumption limits (POSIX.1-2001) */ +/* Solaris defines RLIM_INFINITY as (rlim_t)-3, so POSIX_RLIMIT_INFINITY is below -1 */ +#ifdef __sun +# define POSIX_RLIM_VALID(v) ((v) >= -1 || (v) == (zend_long) RLIM_INFINITY) +#else +# define POSIX_RLIM_VALID(v) ((v) >= -1) +#endif + +/* Set system resource consumption limits (POSIX.1-2001) */ PHP_FUNCTION(posix_setrlimit) { struct rlimit rl; @@ -1229,12 +1236,12 @@ PHP_FUNCTION(posix_setrlimit) Z_PARAM_LONG(max) ZEND_PARSE_PARAMETERS_END(); - if (cur < -1) { + if (!POSIX_RLIM_VALID(cur)) { zend_argument_value_error(2, "must be greater or equal to -1"); RETURN_THROWS(); } - if (max < -1) { + if (!POSIX_RLIM_VALID(max)) { zend_argument_value_error(3, "must be greater or equal to -1"); RETURN_THROWS(); } @@ -1254,7 +1261,6 @@ PHP_FUNCTION(posix_setrlimit) RETURN_TRUE; } -/* }}} */ #endif /* HAVE_SETRLIMIT */