mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
Fix GlobIterator without constructor breaks count() (#18314)
As reported by OpenAI AARDVARK.
This commit is contained in:
parent
fd7ebd4d15
commit
1684c52a88
2 changed files with 20 additions and 6 deletions
|
@ -1599,12 +1599,12 @@ PHP_METHOD(GlobIterator, count)
|
||||||
RETURN_THROWS();
|
RETURN_THROWS();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The spl_filesystem_object_get_method_check() function is called prior to calling this function.
|
if (EXPECTED(spl_intern_is_glob(intern))) {
|
||||||
* Therefore, the directory entry cannot be NULL. However, if it is not NULL, then it must be a glob iterator
|
RETURN_LONG(php_glob_stream_get_count(intern->u.dir.dirp, NULL));
|
||||||
* by construction. */
|
} else {
|
||||||
ZEND_ASSERT(spl_intern_is_glob(intern));
|
/* This can happen by avoiding constructors in specially-crafted code. */
|
||||||
|
zend_throw_error(NULL, "GlobIterator is not initialized");
|
||||||
RETURN_LONG(php_glob_stream_get_count(intern->u.dir.dirp, NULL));
|
}
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
#endif /* HAVE_GLOB */
|
#endif /* HAVE_GLOB */
|
||||||
|
|
14
ext/spl/tests/GlobIterator_constructor_count.phpt
Normal file
14
ext/spl/tests/GlobIterator_constructor_count.phpt
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
--TEST--
|
||||||
|
GlobIterator without constructor breaks count()
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
$rc = new ReflectionClass(GlobIterator::class);
|
||||||
|
$in = $rc->newInstanceWithoutConstructor();
|
||||||
|
try {
|
||||||
|
count($in);
|
||||||
|
} catch (Error $e) {
|
||||||
|
echo $e->getMessage(), "\n";
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
GlobIterator is not initialized
|
Loading…
Add table
Add a link
Reference in a new issue