Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6bd0175

Browse files
Prevent fclose on underlying SplFileObject file stream. (#7920)
1 parent 5cf2659 commit 6bd0175

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

‎ext/spl/spl_directory.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,9 @@ static zend_result spl_filesystem_file_open(spl_filesystem_object *intern, bool
334334
return FAILURE;
335335
}
336336

337+
/* prevent closing the stream outside of SplFileObject */
338+
intern->u.file.stream->flags |= PHP_STREAM_FLAG_NO_FCLOSE;
339+
337340
/*
338341
if (intern->u.file.zcontext) {
339342
//zend_list_addref(Z_RES_VAL(intern->u.file.zcontext));

‎ext/spl/tests/bug81691.phpt‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Bug #81691 fclose on SplFileObject stream
3+
--FILE--
4+
<?php
5+
$obj = new SplFileObject(__FILE__);
6+
$resources = get_resources();
7+
fclose(end($resources));
8+
9+
var_dump($obj->fgets());
10+
11+
?>
12+
--EXPECTF--
13+
Warning: fclose(): %d is not a valid stream resource in %s on line %d
14+
string(6) "<?php
15+
"

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /