Skip to content

Add missing ZPP checks in SPL Directory #8325

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 3 commits into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 9 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ PHP 8.2 UPGRADE NOTES
array_change_key_case and sorting with SORT_FLAG_CASE use ASCII case
conversion.

- SPL:
. The following methods now enforce their signature:
* SplFileInfo::_bad_state_ex()
* SplFileObject::getCsvControl()
* SplFileObject::fflush()
* SplFileObject::ftell()
* SplFileObject::fgetc()
* SplFileObject::fpassthru()

========================================
2. New Features
========================================
Expand Down
23 changes: 23 additions & 0 deletions ext/spl/spl_directory.c
Original file line number Diff line number Diff line change
Expand Up @@ -1399,6 +1399,9 @@ PHP_METHOD(SplFileInfo, __debugInfo)
/* {{{ */
PHP_METHOD(SplFileInfo, _bad_state_ex)
{
if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}
zend_throw_error(NULL, "The parent constructor was not called: the object is in an invalid state");
}
/* }}} */
Expand Down Expand Up @@ -2476,6 +2479,10 @@ PHP_METHOD(SplFileObject, getCsvControl)
spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(ZEND_THIS);
char delimiter[2], enclosure[2], escape[2];

if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}

array_init(return_value);

delimiter[0] = intern->u.file.delimiter;
Expand Down Expand Up @@ -2517,6 +2524,10 @@ PHP_METHOD(SplFileObject, fflush)
{
spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(ZEND_THIS);

if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}

CHECK_SPL_FILE_OBJECT_IS_INITIALIZED(intern);

RETURN_BOOL(!php_stream_flush(intern->u.file.stream));
Expand All @@ -2528,6 +2539,10 @@ PHP_METHOD(SplFileObject, ftell)
spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(ZEND_THIS);
zend_long ret;

if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}

CHECK_SPL_FILE_OBJECT_IS_INITIALIZED(intern);

ret = php_stream_tell(intern->u.file.stream);
Expand Down Expand Up @@ -2562,6 +2577,10 @@ PHP_METHOD(SplFileObject, fgetc)
char buf[2];
int result;

if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}

CHECK_SPL_FILE_OBJECT_IS_INITIALIZED(intern);

spl_filesystem_file_free_line(intern);
Expand All @@ -2585,6 +2604,10 @@ PHP_METHOD(SplFileObject, fpassthru)
{
spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(ZEND_THIS);

if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}

CHECK_SPL_FILE_OBJECT_IS_INITIALIZED(intern);

RETURN_LONG(php_stream_passthru(intern->u.file.stream));
Expand Down