Skip to content

Commit 36f9542

Browse files
committed
fix to follow each call proper behavior.
a negative pid is acceptable for kill as it represents a process group id while setpgid the pid must be at least 0.
1 parent d8d7783 commit 36f9542

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

ext/posix/posix.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@
4646
#endif
4747

4848
#if (defined(__sun) && !defined(_LP64)) || defined(_AIX)
49+
#define POSIX_PID_MIN LONG_MIN
4950
#define POSIX_PID_MAX LONG_MAX
5051
#else
52+
#define POSIX_PID_MIN INT_MIN
5153
#define POSIX_PID_MAX INT_MAX
5254
#endif
5355

@@ -124,10 +126,10 @@ ZEND_GET_MODULE(posix)
124126
} \
125127
RETURN_TRUE;
126128

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(); \
129+
#define PHP_POSIX_CHECK_PID(pid, lower, upper) \
130+
if (pid < lower || pid > upper) { \
131+
zend_argument_value_error(1, "must be between " ZEND_LONG_FMT " and " ZEND_LONG_FMT, lower, upper); \
132+
RETURN_THROWS(); \
131133
}
132134

133135
/* {{{ Send a signal to a process (POSIX.1, 3.3.2) */
@@ -141,7 +143,7 @@ PHP_FUNCTION(posix_kill)
141143
Z_PARAM_LONG(sig)
142144
ZEND_PARSE_PARAMETERS_END();
143145

144-
PHP_POSIX_CHECK_PID(pid)
146+
PHP_POSIX_CHECK_PID(pid, POSIX_PID_MIN, POSIX_PID_MAX)
145147

146148
if (kill(pid, sig) < 0) {
147149
POSIX_G(last_error) = errno;
@@ -305,7 +307,7 @@ PHP_FUNCTION(posix_setpgid)
305307
Z_PARAM_LONG(pgid)
306308
ZEND_PARSE_PARAMETERS_END();
307309

308-
PHP_POSIX_CHECK_PID(pid)
310+
PHP_POSIX_CHECK_PID(pid, 0, POSIX_PID_MAX)
309311

310312
if (setpgid(pid, pgid) < 0) {
311313
POSIX_G(last_error) = errno;

ext/posix/tests/posix_kill_error.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ $sig = 999;
1313
var_dump( posix_kill($pid, 999) );
1414

1515
echo "\n-- Testing posix_kill() function with negative pid --\n";
16-
$pid = -1;
16+
$pid = -999;
1717
$sig = 9;
1818
var_dump( posix_kill($pid, 999) );
1919

ext/posix/tests/posix_kill_pidoverflow.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ try {
2020
}
2121
?>
2222
--EXPECTF--
23-
posix_kill(): Argument #1 ($process_id) must be between -1 and %d
24-
posix_kill(): Argument #1 ($process_id) must be between -1 and %d
23+
posix_kill(): Argument #1 ($process_id) must be between %d and %d
24+
posix_kill(): Argument #1 ($process_id) must be between %d and %d

ext/posix/tests/posix_setpgid_error.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ try {
1818
}
1919
?>
2020
--EXPECTF--
21-
posix_setpgid(): Argument #1 ($process_id) must be between -1 and %d
22-
posix_setpgid(): Argument #1 ($process_id) must be between -1 and %d
21+
posix_setpgid(): Argument #1 ($process_id) must be between 0 and %d
22+
posix_setpgid(): Argument #1 ($process_id) must be between 0 and %d

0 commit comments

Comments
 (0)