Skip to content

Commit 8683d17

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: Fix GH-7809: Cloning a faked SplFileInfo object may segfault
2 parents aab5296 + 0ed39ed commit 8683d17

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

ext/spl/spl_directory.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,12 @@ static zend_object *spl_filesystem_object_clone(zend_object *old_object)
385385

386386
switch (source->type) {
387387
case SPL_FS_INFO:
388-
intern->path = zend_string_copy(source->path);
389-
intern->file_name = zend_string_copy(source->file_name);
388+
if (source->path != NULL) {
389+
intern->path = zend_string_copy(source->path);
390+
}
391+
if (source->file_name != NULL) {
392+
intern->file_name = zend_string_copy(source->file_name);
393+
}
390394
break;
391395
case SPL_FS_DIR:
392396
spl_filesystem_dir_open(intern, source->path);

ext/spl/tests/gh7809.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Bug GH-7809 (Cloning a faked SplFileInfo object may segfault)
3+
--FILE--
4+
<?php
5+
class MySplFileInfo extends SplFileInfo {
6+
public function __construct(string $filename) {}
7+
}
8+
9+
$sfi = new MySplFileInfo("foo");
10+
clone $sfi;
11+
?>
12+
--EXPECT--

0 commit comments

Comments
 (0)