Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions ext/standard/io_poll.c
Original file line number Diff line number Diff line change
Expand Up @@ -804,12 +804,17 @@ PHP_METHOD(Io_Poll_Context, wait)
if (max_events <= 0) {
max_events = 64;
}
} else if (max_events <= 0) {
} else if (UNEXPECTED(max_events <= 0)) {
zend_argument_value_error(2, "must be greater than 0");
RETURN_THROWS();
#if SIZEOF_INT < SIZEOF_ZEND_LONG
} else if (UNEXPECTED(max_events > INT_MAX)) {
zend_argument_value_error(2, "must be lower than or equal to %d", INT_MAX);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: must be less than or equal to %d

RETURN_THROWS();
#endif
}

php_poll_event *events = safe_emalloc(max_events, sizeof(*events), 0);
php_poll_event *events = safe_emalloc((size_t) max_events, sizeof(*events), 0);
int num_events = php_poll_wait(intern->ctx, events, (int) max_events, timeout ? &timeout_ts : NULL);

if (num_events < 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,27 @@ try {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}

try {
$poll_ctx->wait(maxEvents: PHP_INT_MIN);
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}

try {
$poll_ctx->wait(maxEvents: -1);
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}

try {
$poll_ctx->wait(maxEvents: 0);
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}

?>
--EXPECT--
ValueError: Io\Poll\Context::wait(): Argument #1 ($timeout) must not be negative
ValueError: Io\Poll\Context::wait(): Argument #2 ($maxEvents) must be greater than 0
ValueError: Io\Poll\Context::wait(): Argument #2 ($maxEvents) must be greater than 0
ValueError: Io\Poll\Context::wait(): Argument #2 ($maxEvents) must be greater than 0
23 changes: 23 additions & 0 deletions ext/standard/tests/poll/poll_ctx_wait_error_int64.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
Io\Poll\Context::wait(): Parameter validation upper limit
--SKIPIF--
<?php
if (PHP_INT_SIZE <= 4) {
die("skip this test is for > 32bit platforms only");
}
?>
--FILE--
<?php
require_once __DIR__ . '/poll.inc';

$poll_ctx = new Io\Poll\Context();

try {
$poll_ctx->wait(maxEvents: PHP_INT_MAX);
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}

?>
--EXPECTF--
ValueError: Io\Poll\Context::wait(): Argument #2 ($maxEvents) must be lower than or equal to %d
Loading