Skip to content

Fix GH-7809: Cloning a faked SplFileInfo object may segfault #7814

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions ext/spl/spl_directory.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,12 @@ static zend_object *spl_filesystem_object_clone(zend_object *old_object)

switch (source->type) {
case SPL_FS_INFO:
intern->path = zend_string_copy(source->path);
intern->file_name = zend_string_copy(source->file_name);
if (source->path != NULL) {
intern->path = zend_string_copy(source->path);
}
if (source->file_name != NULL) {
intern->file_name = zend_string_copy(source->file_name);
}
break;
case SPL_FS_DIR:
spl_filesystem_dir_open(intern, source->path);
Expand Down
12 changes: 12 additions & 0 deletions ext/spl/tests/gh7809.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
Bug GH-7809 (Cloning a faked SplFileInfo object may segfault)
--FILE--
<?php
class MySplFileInfo extends SplFileInfo {
public function __construct(string $filename) {}
}

$sfi = new MySplFileInfo("foo");
clone $sfi;
?>
--EXPECT--