Skip to content

Commit b461e6b

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Fixed bug #79710
2 parents 5d7ff25 + 2f56b00 commit b461e6b

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

ext/spl/spl_directory.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ static void spl_filesystem_object_destroy_object(zend_object *object) /* {{{ */
9595
php_stream_pclose(intern->u.file.stream);
9696
}
9797
intern->u.file.stream = NULL;
98+
ZVAL_UNDEF(&intern->u.file.zresource);
9899
}
99100
break;
100101
default:
@@ -1927,12 +1928,16 @@ static int spl_filesystem_file_call(spl_filesystem_object *intern, zend_function
19271928
{
19281929
zend_fcall_info fci;
19291930
zend_fcall_info_cache fcic;
1930-
zval *zresource_ptr = &intern->u.file.zresource;
1931+
zval *zresource_ptr = &intern->u.file.zresource, *params;
19311932
int result;
19321933
int num_args = pass_num_args + (arg2 ? 2 : 1);
19331934

1934-
zval *params = (zval*)safe_emalloc(num_args, sizeof(zval), 0);
1935+
if (Z_ISUNDEF_P(zresource_ptr)) {
1936+
zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized");
1937+
return FAILURE;
1938+
}
19351939

1940+
params = (zval*)safe_emalloc(num_args, sizeof(zval), 0);
19361941
params[0] = *zresource_ptr;
19371942

19381943
if (arg2) {

ext/spl/tests/bug79710.phpt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
--TEST--
2+
Bug #79710: Reproducible segfault in error_handler during GC involved an SplFileObject
3+
--FILE--
4+
<?php
5+
6+
class Target
7+
{
8+
public $sfo;
9+
public function __construct($sfo) {
10+
$this->sfo = $sfo;
11+
}
12+
public function __destruct() {
13+
// If the SplFileObject is destructed first,
14+
// underlying FD is no longer valid and will cause error upon calling flock
15+
$this->sfo->flock(2);
16+
}
17+
}
18+
19+
class Run
20+
{
21+
static $sfo;
22+
static $foo;
23+
public static function main() {
24+
// Creation ordering is important for repro
25+
// $sfo needed to be destructed before $foo.
26+
Run::$sfo = new SplTempFileObject();
27+
Run::$foo = new Target(Run::$sfo);
28+
}
29+
}
30+
31+
Run::main();
32+
33+
?>
34+
--EXPECTF--
35+
Fatal error: Uncaught RuntimeException: Object not initialized in %s:%d
36+
Stack trace:
37+
#0 %s(%d): SplFileObject->flock(2)
38+
#1 [internal function]: Target->__destruct()
39+
#2 {main}
40+
thrown in %s on line %d

0 commit comments

Comments
 (0)