Skip to content

Commit b97b405

Browse files
committed
Fix GH-20678: resource created by GlobIterator crashes with fclose().
1 parent 4969ef1 commit b97b405

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

ext/spl/spl_directory.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,11 @@ static void spl_filesystem_dir_open(spl_filesystem_object* intern, zend_string *
306306
intern->type = SPL_FS_DIR;
307307
intern->u.dir.dirp = php_stream_opendir(ZSTR_VAL(path), REPORT_ERRORS, FG(default_context));
308308

309+
if (intern->u.dir.dirp) {
310+
/* we prevent potential UAF with conflicting explicit fclose(), relying on the object destructor for this */
311+
intern->u.dir.dirp->flags |= PHP_STREAM_FLAG_NO_FCLOSE;
312+
}
313+
309314
if (ZSTR_LEN(path) > 1 && IS_SLASH_AT(ZSTR_VAL(path), ZSTR_LEN(path)-1)) {
310315
intern->path = zend_string_init(ZSTR_VAL(path), ZSTR_LEN(path)-1, 0);
311316
} else {

0 commit comments

Comments
 (0)