Skip to content

Commit ce2fdb7

Browse files
committed
ext/pcntl: Also reject too large values in pcntl_alarm()
1 parent 0a900dc commit ce2fdb7

File tree

3 files changed

+35
-28
lines changed

3 files changed

+35
-28
lines changed

ext/pcntl/pcntl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,8 @@ PHP_FUNCTION(pcntl_alarm)
314314
Z_PARAM_LONG(seconds);
315315
ZEND_PARSE_PARAMETERS_END();
316316

317-
if (seconds < 0) {
318-
zend_argument_value_error(1, "must be greater or equal to 0");
317+
if (seconds < 0 || seconds > UINT_MAX) {
318+
zend_argument_value_error(1, "must be between 0 and %u", UINT_MAX);
319319
RETURN_THROWS();
320320
}
321321

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
pcntl_alarm() rejects invalid values
3+
--EXTENSIONS--
4+
pcntl
5+
--FILE--
6+
<?php
7+
8+
try {
9+
pcntl_alarm(-1);
10+
} catch (\ValueError $e) {
11+
echo $e->getMessage() . \PHP_EOL;
12+
}
13+
14+
try {
15+
pcntl_alarm(PHP_INT_MIN);
16+
} catch (\ValueError $e) {
17+
echo $e->getMessage() . \PHP_EOL;
18+
}
19+
20+
try {
21+
pcntl_alarm(PHP_INT_MAX);
22+
} catch (\ValueError $e) {
23+
echo $e->getMessage() . \PHP_EOL;
24+
}
25+
26+
var_dump(pcntl_alarm(0));
27+
28+
?>
29+
--EXPECTF--
30+
pcntl_alarm(): Argument #1 ($seconds) must be between 0 and %d
31+
pcntl_alarm(): Argument #1 ($seconds) must be between 0 and %d
32+
pcntl_alarm(): Argument #1 ($seconds) must be between 0 and %d
33+
int(0)

ext/pcntl/tests/pcntl_alarm_negative_value.phpt

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)