Skip to content

Fix posix_ttyname() returning the stdin terminal for an invalid argument type - #25467

Open
lacatoire wants to merge 1 commit into
php:PHP-8.4from
lacatoire:fix/posix-ttyname-invalid-fd-type-8.4
Open

lacatoire wants to merge 1 commit into
php:PHP-8.4from
lacatoire:fix/posix-ttyname-invalid-fd-type-8.4

Conversation

@lacatoire

@lacatoire lacatoire commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

After warning that the argument is neither an int nor a resource, posix_ttyname() converted it with zval_get_long(). A string, array or object therefore became file descriptor 0 or 1, and the function returned the name of the terminal. Return false after the warning instead, as posix_isatty() already does.

To reproduce, in a terminal:

var_dump(posix_ttyname('abc'));

Before:

Warning: posix_ttyname(): Argument #1 ($file_descriptor) must be of type int|resource, string given in %s on line %d
string(10) "/dev/pts/0"

After:

Warning: posix_ttyname(): Argument #1 ($file_descriptor) must be of type int|resource, string given in %s on line %d
bool(false)

…ent type

After warning that the argument is neither an int nor a resource,
posix_ttyname() converted it with zval_get_long(). A string, array or
object therefore became file descriptor 0 or 1, and the function returned
the name of the terminal. Return false after the warning instead, as
posix_isatty() already does.
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