File tree Expand file tree Collapse file tree 2 files changed +29
-4
lines changed Expand file tree Collapse file tree 2 files changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -124,6 +124,12 @@ ZEND_GET_MODULE(posix)
124
124
} \
125
125
RETURN_TRUE;
126
126
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
+
127
133
/* {{{ Send a signal to a process (POSIX.1, 3.3.2) */
128
134
129
135
PHP_FUNCTION (posix_kill )
@@ -135,10 +141,7 @@ PHP_FUNCTION(posix_kill)
135
141
Z_PARAM_LONG (sig )
136
142
ZEND_PARSE_PARAMETERS_END ();
137
143
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 )
142
145
143
146
if (kill (pid , sig ) < 0 ) {
144
147
POSIX_G (last_error ) = errno ;
@@ -302,6 +305,8 @@ PHP_FUNCTION(posix_setpgid)
302
305
Z_PARAM_LONG (pgid )
303
306
ZEND_PARSE_PARAMETERS_END ();
304
307
308
+ PHP_POSIX_CHECK_PID (pid )
309
+
305
310
if (setpgid (pid , pgid ) < 0 ) {
306
311
POSIX_G (last_error ) = errno ;
307
312
RETURN_FALSE ;
Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments