Commit 602ba3ac970 for php
commit 602ba3ac97027080d074d18cb590d6fd105789ff
Author: Jorg Sowa <jorg.sowa@gmail.com>
Date: Fri Oct 16 20:49:45 2026 +0200
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
diff --git a/NEWS b/NEWS
index f3377bef23a..ce0aa590776 100644
--- a/NEWS
+++ b/NEWS
@@ -75,6 +75,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 e4c2b91678e..b8d2e5a21a2 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 */