Skip to content

Fix GH-25574: FFI passes bools to variadic functions as uint8 - #25576

Open
Marti2203 wants to merge 2 commits into
php:PHP-8.4from
Marti2203:fix-gh25574-ffi-variadic-bool
Open

Marti2203 wants to merge 2 commits into
php:PHP-8.4from
Marti2203:fix-gh25574-ffi-variadic-bool

Conversation

@Marti2203

Copy link
Copy Markdown
Contributor

Fixes #25574.

Pass a bool given as a variadic argument as ffi_type_sint32, as the default argument promotions require, instead of ffi_type_uint8, whose upper bytes in the register or stack slot are undefined.

ext/ffi/tests/gh25574.phpt prints eight bools through snprintf() after filling the argument slots with -1; without the change it gives 1 0 1 -256 -255 -256 ... -256. ext/ffi/tests pass.

This issue was found by an LLM-assisted tool and verified manually.

A bool passed as a variadic argument is subject to the default argument
promotions, so the callee reads an int. zend_ffi_pass_var_arg() passed
it as ffi_type_uint8, leaving the upper bytes of the register or stack
slot undefined. Pass it as ffi_type_sint32.
snprintf cannot be resolved without a library name on Windows; call
PHP's own exported ap_php_snprintf through ffi_get_php_dll_name().
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.

1 participant