Skip to content

Commit 4754590

Browse files
committed
Fix GH-14687 segfault on debugging a freed SplObjectIterator instance.
1 parent 42908f9 commit 4754590

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

ext/spl/spl_directory.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ static inline HashTable *spl_filesystem_object_get_debug_info(zend_object *objec
668668
if (intern->type == SPL_FS_DIR) {
669669
#ifdef HAVE_GLOB
670670
pnstr = spl_gen_private_prop_name(spl_ce_DirectoryIterator, "glob", sizeof("glob")-1);
671-
if (php_stream_is(intern->u.dir.dirp ,&php_glob_stream_ops)) {
671+
if (intern->u.dir.dirp && php_stream_is(intern->u.dir.dirp ,&php_glob_stream_ops)) {
672672
ZVAL_STR_COPY(&tmp, intern->path);
673673
} else {
674674
ZVAL_FALSE(&tmp);

ext/spl/tests/gh14687.phpt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
--TEST--
2+
GH-14687 segfault on debugging SplObjectStorage instance after __destruct.
3+
--CREDITS--
4+
YuanchengJiang
5+
--EXTENSIONS--
6+
phar
7+
--INI--
8+
phar.require_hash=0
9+
phar.readonly=0
10+
--FILE--
11+
<?php
12+
$fname = __DIR__ . '/' . basename(__FILE__, '.php') . '.phar.zip';
13+
$phar = new Phar($fname);
14+
class HasDestructor {
15+
public function __destruct() {
16+
var_dump($GLOBALS['s']);
17+
}
18+
}
19+
$s = new SplObjectStorage();
20+
$s[$phar] = new HasDestructor();
21+
--EXPECT--
22+
object(SplObjectStorage)#2 (1) {
23+
["storage":"SplObjectStorage":private]=>
24+
array(1) {
25+
[0]=>
26+
array(2) {
27+
["obj"]=>
28+
object(Phar)#1 (3) {
29+
["pathName":"SplFileInfo":private]=>
30+
string(0) ""
31+
["glob":"DirectoryIterator":private]=>
32+
bool(false)
33+
["subPathName":"RecursiveDirectoryIterator":private]=>
34+
string(0) ""
35+
}
36+
["inf"]=>
37+
object(HasDestructor)#3 (0) {
38+
}
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)