Skip to content

Commit a0e7474

Browse files
committed
fix and update tests.
1 parent 247e7c1 commit a0e7474

File tree

4 files changed

+32
-12
lines changed

4 files changed

+32
-12
lines changed

ext/posix/posix.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ ZEND_GET_MODULE(posix)
126126
} \
127127
RETURN_TRUE;
128128

129-
#define PHP_POSIX_CHECK_PID(pid, lower, upper) \
129+
#define PHP_POSIX_CHECK_PID(pid, arg, lower, upper) \
130130
if (pid < lower || pid > upper) { \
131-
zend_argument_value_error(1, "must be between " ZEND_LONG_FMT " and " ZEND_LONG_FMT, lower, upper); \
131+
zend_argument_value_error(arg, "must be between " ZEND_LONG_FMT " and " ZEND_LONG_FMT, lower, upper); \
132132
RETURN_THROWS(); \
133133
}
134134

@@ -143,7 +143,7 @@ PHP_FUNCTION(posix_kill)
143143
Z_PARAM_LONG(sig)
144144
ZEND_PARSE_PARAMETERS_END();
145145

146-
PHP_POSIX_CHECK_PID(pid, POSIX_PID_MIN, POSIX_PID_MAX)
146+
PHP_POSIX_CHECK_PID(pid, 1, POSIX_PID_MIN, POSIX_PID_MAX)
147147

148148
if (kill(pid, sig) < 0) {
149149
POSIX_G(last_error) = errno;
@@ -307,8 +307,8 @@ PHP_FUNCTION(posix_setpgid)
307307
Z_PARAM_LONG(pgid)
308308
ZEND_PARSE_PARAMETERS_END();
309309

310-
PHP_POSIX_CHECK_PID(pid, 0, POSIX_PID_MAX)
311-
PHP_POSIX_CHECK_PID(pgid, 0, POSIX_PID_MAX)
310+
PHP_POSIX_CHECK_PID(pid, 1, 0, POSIX_PID_MAX)
311+
PHP_POSIX_CHECK_PID(pgid, 2, 0, POSIX_PID_MAX)
312312

313313
if (setpgid(pid, pgid) < 0) {
314314
POSIX_G(last_error) = errno;
@@ -348,7 +348,7 @@ PHP_FUNCTION(posix_getsid)
348348
Z_PARAM_LONG(val)
349349
ZEND_PARSE_PARAMETERS_END();
350350

351-
PHP_POSIX_CHECK_PID(val, 0, POSIX_PID_MAX)
351+
PHP_POSIX_CHECK_PID(val, 1, 0, POSIX_PID_MAX)
352352

353353
if ((val = getsid(val)) < 0) {
354354
POSIX_G(last_error) = errno;
@@ -1219,7 +1219,7 @@ PHP_FUNCTION(posix_setrlimit)
12191219
RETURN_THROWS();
12201220
}
12211221

1222-
if (cur > max) {
1222+
if (max > -1 && cur > max) {
12231223
zend_argument_value_error(2, "must be lower or equal to " ZEND_LONG_FMT, max);
12241224
RETURN_THROWS();
12251225
}

ext/posix/tests/posix_getsid_error.phpt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ PHP Testfest Berlin 2009-05-10
99
posix
1010
--FILE--
1111
<?php
12-
var_dump( posix_getsid(-1) );
12+
try {
13+
posix_getsid(-1);
14+
} catch (\ValueError $e) {
15+
echo $e->getMessage(), PHP_EOL;
16+
}
1317
?>
14-
--EXPECT--
15-
bool(false)
18+
--EXPECTF--
19+
posix_getsid(): Argument #1 ($process_id) must be between 0 and %d

ext/posix/tests/posix_setpgid_error.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,19 @@ try {
1616
} catch (\ValueError $e) {
1717
echo $e->getMessage(), PHP_EOL;
1818
}
19+
try {
20+
posix_setpgid(1, PHP_INT_MAX);
21+
} catch (\ValueError $e) {
22+
echo $e->getMessage(), PHP_EOL;
23+
}
24+
try {
25+
posix_setpgid(1, -2);
26+
} catch (\ValueError $e) {
27+
echo $e->getMessage(), PHP_EOL;
28+
}
1929
?>
2030
--EXPECTF--
2131
posix_setpgid(): Argument #1 ($process_id) must be between 0 and %d
2232
posix_setpgid(): Argument #1 ($process_id) must be between 0 and %d
33+
posix_setpgid(): Argument #2 ($process_group_id) must be between 0 and %d
34+
posix_setpgid(): Argument #2 ($process_group_id) must be between 0 and %d

ext/posix/tests/posix_setrlimit.phpt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@ if (str_contains(PHP_OS, 'FreeBSD')) die('skip different behavior on FreeBSD');
1212
<?php
1313

1414
var_dump(posix_setrlimit(POSIX_RLIMIT_NOFILE, 128, 128));
15-
var_dump(posix_setrlimit(POSIX_RLIMIT_NOFILE, 129, 128));
15+
try {
16+
posix_setrlimit(POSIX_RLIMIT_NOFILE, 129, 128);
17+
} catch (\ValueError $e) {
18+
echo $e->getMessage(), PHP_EOL;
19+
}
1620

1721
?>
1822
--EXPECT--
1923
bool(true)
20-
bool(false)
24+
posix_setrlimit(): Argument #2 ($soft_limit) must be lower or equal to 128

0 commit comments

Comments
 (0)