Skip to content

ext/posix: posix_isatty() fix use-of-uninitialized-value #11676

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ext/posix/posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,9 @@ PHP_FUNCTION(posix_isatty)
if (!zend_parse_arg_long(z_fd, &fd, /* is_null */ NULL, /* check_null */ false, /* arg_num */ 1)) {
php_error_docref(NULL, E_WARNING, "Argument #1 ($file_descriptor) must be of type int|resource, %s given",
zend_zval_value_name(z_fd));
fd = zval_get_long(z_fd);
RETURN_FALSE;
}
fd = zval_get_long(z_fd);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this part looks redundant, no? fd is written to by zend_parse_arg_long, but only if successful.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah indeed!

}

/* A valid file descriptor must fit in an int and be positive */
Expand Down
4 changes: 0 additions & 4 deletions ext/posix/tests/posix_isatty_manual_zpp.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,9 @@ Warning: posix_isatty(): Argument #1 ($file_descriptor) must be of type int|reso
bool(false)
class:
Warning: posix_isatty(): Argument #1 ($file_descriptor) must be of type int|resource, stdClass given in %s on line %d

Warning: Object of class stdClass could not be converted to int in %s on line %d
bool(false)
stringable class:
Warning: posix_isatty(): Argument #1 ($file_descriptor) must be of type int|resource, classWithToString given in %s on line %d

Warning: Object of class classWithToString could not be converted to int in %s on line %d
bool(false)
int castable class:
Warning: posix_isatty(): Argument #1 ($file_descriptor) must be of type int|resource, GMP given in %s on line %d
Expand Down