1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Merge branch 'PHP-8.3' into PHP-8.4

* PHP-8.3:
  Fix GH-20678: resource created by GlobIterator crashes with fclose().
This commit is contained in:
David Carlier
2025-12-14 11:58:41 +00:00
3 changed files with 23 additions and 0 deletions

4
NEWS
View File

@@ -16,6 +16,10 @@ PHP NEWS
- LDAP:
. Fix memory leak in ldap_set_options(). (ndossche)
- SPL:
. Fixed bug GH-20678 (resource created by GlobIterator crashes with fclose()).
(David Carlier)
- Standard:
. Fix error check for proc_open() command. (ndossche)

View File

@@ -297,6 +297,11 @@ static void spl_filesystem_dir_open(spl_filesystem_object* intern, zend_string *
intern->type = SPL_FS_DIR;
intern->u.dir.dirp = php_stream_opendir(ZSTR_VAL(path), REPORT_ERRORS, FG(default_context));
if (intern->u.dir.dirp) {
/* we prevent potential UAF with conflicting explicit fclose(), relying on the object destructor for this */
intern->u.dir.dirp->flags |= PHP_STREAM_FLAG_NO_FCLOSE;
}
if (ZSTR_LEN(path) > 1 && IS_SLASH_AT(ZSTR_VAL(path), ZSTR_LEN(path)-1)) {
intern->path = zend_string_init(ZSTR_VAL(path), ZSTR_LEN(path)-1, 0);
} else {

View File

@@ -0,0 +1,14 @@
--TEST--
GH-20678 (resource created by GlobalIterator crashes when it is called with fclose())
--CREDITS--
chongwick
--FILE--
<?php
$iter = new GlobIterator(__DIR__ . '/*.abcdefghij');
$resources = get_resources();
$resource = end($resources);
fclose($resource);
?>
--EXPECTF--
Warning: fclose(): %d is not a valid stream resource in %s on line %d