Skip to content

Commit 247e7c1

Browse files
committed
ext/posix: value ranges check for posix_setrlimit and posix_setpgid
setpgid accepts values from 0 to "PID_MAX". for setrlimit the culprit is using zend_long to represent rlim_t but at least we accept -1 for RLIM_INFINITY, however rl_cur should not be greater than rl_max value.
1 parent b30ccf9 commit 247e7c1

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

ext/posix/posix.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ PHP_FUNCTION(posix_setpgid)
308308
ZEND_PARSE_PARAMETERS_END();
309309

310310
PHP_POSIX_CHECK_PID(pid, 0, POSIX_PID_MAX)
311+
PHP_POSIX_CHECK_PID(pgid, 0, POSIX_PID_MAX)
311312

312313
if (setpgid(pid, pgid) < 0) {
313314
POSIX_G(last_error) = errno;
@@ -347,6 +348,8 @@ PHP_FUNCTION(posix_getsid)
347348
Z_PARAM_LONG(val)
348349
ZEND_PARSE_PARAMETERS_END();
349350

351+
PHP_POSIX_CHECK_PID(val, 0, POSIX_PID_MAX)
352+
350353
if ((val = getsid(val)) < 0) {
351354
POSIX_G(last_error) = errno;
352355
RETURN_FALSE;
@@ -1201,6 +1204,26 @@ PHP_FUNCTION(posix_setrlimit)
12011204
Z_PARAM_LONG(max)
12021205
ZEND_PARSE_PARAMETERS_END();
12031206

1207+
if (res < -1) {
1208+
zend_argument_value_error(1, "must be greater or equal to -1");
1209+
RETURN_THROWS();
1210+
}
1211+
1212+
if (cur < -1) {
1213+
zend_argument_value_error(2, "must be greater or equal to -1");
1214+
RETURN_THROWS();
1215+
}
1216+
1217+
if (max < -1) {
1218+
zend_argument_value_error(3, "must be greater or equal to -1");
1219+
RETURN_THROWS();
1220+
}
1221+
1222+
if (cur > max) {
1223+
zend_argument_value_error(2, "must be lower or equal to " ZEND_LONG_FMT, max);
1224+
RETURN_THROWS();
1225+
}
1226+
12041227
rl.rlim_cur = cur;
12051228
rl.rlim_max = max;
12061229

0 commit comments

Comments
 (0)