Skip to content

Fix wrong argument number in fsockopen/pfsockopen timeout error - #23431

Open
lacatoire wants to merge 1 commit into
php:PHP-8.4from
lacatoire:fix/fsockopen-arg-num-8.4
Open

Fix wrong argument number in fsockopen/pfsockopen timeout error#23431
lacatoire wants to merge 1 commit into
php:PHP-8.4from
lacatoire:fix/fsockopen-arg-num-8.4

Conversation

@lacatoire

Copy link
Copy Markdown
Member

php_fsockopen_stream() called zend_argument_value_error(6, ...) for the $timeout parameter, but $timeout is the 5th argument. Because get_function_arg_name(func, arg_num) returns NULL when arg_num exceeds the actual argument count, the error message reported the wrong number and dropped the parameter name.

The format string also used ZEND_ULONG_FMT (which expects a zend_ulong) but received a double expression — undefined behavior in C. This is fixed by adding a (zend_ulong) cast.

Before:

ValueError: fsockopen(): Argument #6 must be -1 or between 0 and 4294967295

After:

ValueError: fsockopen(): Argument #5 ($timeout) must be -1 or between 0 and 18446744073709

The same fix applies to pfsockopen(), which delegates to the same internal helper.

A regression test is included; it does not require network connectivity since the ValueError is raised before any connection attempt.

php_fsockopen_stream() called zend_argument_value_error(6, ...) for the
$timeout parameter, but $timeout is the 5th argument. This caused the
error message to show "Argument php#6" with no parameter name, since
get_function_arg_name() returns NULL when arg_num exceeds the actual
argument count.

The format string also contained ZEND_ULONG_FMT (which expects a zend_ulong)
but received a double expression, causing undefined behavior. This is fixed
by casting to zend_ulong before the call.

@LamentXU123 LamentXU123 left a comment

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.

in 32-bits. zend_ulong is uint32_t. So you can't directly convert double to zend_ulong in all platforms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants