Skip to content

Commit a84a097

Browse files
committed
finally only posix_setpgid has pid_t argument.
1 parent 4a77b74 commit a84a097

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

ext/posix/posix.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ ZEND_GET_MODULE(posix)
124124
} \
125125
RETURN_TRUE;
126126

127+
#define PHP_POSIX_CHECK_PID(pid) \
128+
if (pid < -1 || pid > POSIX_PID_MAX) { \
129+
zend_argument_value_error(1, "must be between -1 and " ZEND_LONG_FMT, POSIX_PID_MAX); \
130+
RETURN_THROWS(); \
131+
}
132+
127133
/* {{{ Send a signal to a process (POSIX.1, 3.3.2) */
128134

129135
PHP_FUNCTION(posix_kill)
@@ -135,10 +141,7 @@ PHP_FUNCTION(posix_kill)
135141
Z_PARAM_LONG(sig)
136142
ZEND_PARSE_PARAMETERS_END();
137143

138-
if (pid < -1 || pid > POSIX_PID_MAX) {
139-
zend_argument_value_error(1, "must be between -1 and " ZEND_LONG_FMT, POSIX_PID_MAX);
140-
RETURN_THROWS();
141-
}
144+
PHP_POSIX_CHECK_PID(pid)
142145

143146
if (kill(pid, sig) < 0) {
144147
POSIX_G(last_error) = errno;
@@ -302,6 +305,8 @@ PHP_FUNCTION(posix_setpgid)
302305
Z_PARAM_LONG(pgid)
303306
ZEND_PARSE_PARAMETERS_END();
304307

308+
PHP_POSIX_CHECK_PID(pid)
309+
305310
if (setpgid(pid, pgid) < 0) {
306311
POSIX_G(last_error) = errno;
307312
RETURN_FALSE;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
posix_setpgid() with wrong pid values
3+
--EXTENSIONS--
4+
posix
5+
--FILE--
6+
<?php
7+
try {
8+
posix_setpgid(PHP_INT_MAX, 1);
9+
} catch (\ValueError $e) {
10+
echo $e->getMessage(), PHP_EOL;
11+
}
12+
try {
13+
posix_setpgid(-2, 1);
14+
} catch (\ValueError $e) {
15+
echo $e->getMessage(), PHP_EOL;
16+
}
17+
?>
18+
--EXPECTF--
19+
posix_setpgid(): Argument #1 ($process_id) must be between -1 and %d
20+
posix_setpgid(): Argument #1 ($process_id) must be between -1 and %d

0 commit comments

Comments
 (0)