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 count for --repeat with an unchecked atoi(), so a value below 1 wrapped num_repeats negative and made the post-execution repeat loop run forever, while overflowing input relied on undefined atoi() behavior. The option now parses its argument with ZEND_STRTOL and rejects empty, non-numeric, non-positive, or beyond-INT_MAX values with a usage error before any execution, like the other invalid CLI option diagnostics. A phpt regression test drives php --repeat=0, --repeat=-2, --repeat=abc, and an overflow value through a timeout-bounded exec and asserts the usage error; it fails on the unpatched build and passes after the fix, and the full sapi/cli/tests suite shows zero new failures. Sibling audit: the strtol() calls in php_cli_server.c parse host:port strings where invalid values surface later as bind errors, and lint mode's do_repeat re-entry is safe now that num_repeats >= 1 is guaranteed.

--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