Skip to content

[CLI] Reject non-positive or overflowing --repeat values - #280

Open
iliaal wants to merge 1 commit into
PHP-8.4from
fix/cli-repeat-validate-84
Open

[CLI] Reject non-positive or overflowing --repeat values#280
iliaal wants to merge 1 commit into
PHP-8.4from
fix/cli-repeat-validate-84

Conversation

@iliaal

@iliaal iliaal commented Aug 24, 2026

Copy link
Copy Markdown
Owner

The CLI SAPI parsed the --repeat count with an unchecked atoi(), so a value below 1 wrapped num_repeats negative and made the repeat loop run forever, while overflowing input relied on undefined atoi() behavior. Parsing now uses ZEND_STRTOL and rejects empty, non-numeric, non-positive, and above-INT_MAX values, range-checking the long result against INT_MAX, with a usage error before execution. A phpt test drives --repeat=0, --repeat=-2, --repeat=abc and an overflow value through a timeout-bounded exec and asserts the usage error; it fails unpatched and passes fixed.

--repeat parsed its count with an unchecked atoi(), so a value below 1
wrapped the repeat counter negative and looped the request forever, and
overflowing input relied on undefined atoi behavior. The value is now
parsed with ZEND_STRTOL and anything that is empty, not fully numeric,
below 1, or beyond INT_MAX is rejected with a usage error before any
execution. Sibling audit: php_cli_server.c strtol usages parse host:port
with bind errors as the failure path, and the lint-mode do_repeat path is
safe now that num_repeats >= 1 is guaranteed.
@iliaal iliaal closed this Aug 24, 2026
@iliaal iliaal reopened this Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant