diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c index 116185846868d..0ba11f4800715 100644 --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@ -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); diff --git a/ext/spl/tests/gh7809.phpt b/ext/spl/tests/gh7809.phpt new file mode 100644 index 0000000000000..6406bef6c1438 --- /dev/null +++ b/ext/spl/tests/gh7809.phpt @@ -0,0 +1,12 @@ +--TEST-- +Bug GH-7809 (Cloning a faked SplFileInfo object may segfault) +--FILE-- + +--EXPECT--