Skip to content
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
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ PHP NEWS
- Session:
. Fixed session upload progress to respect session.use_only_cookies.
(jorgsowa)
. Fixed files save handler GC following symlinked subdirectories when
session.save_path sets a directory depth. (Jorg Sowa)

- SimpleXML:
. Fixed a crash with opcache when simplexml_load_string(),
Expand Down
4 changes: 2 additions & 2 deletions ext/session/mod_files.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,8 @@ static int ps_files_cleanup_dir(const zend_string *dirname, zend_long maxlifetim
nrdels++;
}
} else {
/* intermediate depth: recurse into subdirectories */
if (VCWD_STAT(buf, &sbuf) != 0) {
/* intermediate depth: recurse into subdirectories, never through symlinks */
if (VCWD_LSTAT(buf, &sbuf) != 0) {
continue;
}
if (S_ISDIR(sbuf.st_mode)) {
Expand Down
45 changes: 45 additions & 0 deletions ext/session/tests/mod_files/gc_dirdepth_symlink.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
--TEST--
session GC with save_path dirdepth does not follow symlinked subdirectories
--EXTENSIONS--
session
--SKIPIF--
<?php
include(__DIR__ . '/../skipif.inc');
$probe = __DIR__ . '/gc_dirdepth_symlink_probe';
@mkdir($probe);
$ok = @symlink($probe, "$probe.lnk");
@rmdir("$probe.lnk") || @unlink("$probe.lnk");
@rmdir($probe);
if (!$ok) die('skip cannot create directory symlinks');
?>
--INI--
session.gc_probability=0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you pin session.gc_maxlifetime=10 here? At 3600, the 2,000-second-old file survives even if GC follows the symlink.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in new commit

session.gc_maxlifetime=10
session.use_strict_mode=0
--FILE--
<?php
$base = __DIR__ . '/gc_dirdepth_symlink';
$outside = "$base-outside";
@mkdir("$base/b", 0777, true);
@mkdir($outside);
symlink($outside, "$base/a");
touch("$outside/sess_a", time() - 2000);

session_save_path("1;$base");
session_id('b0');
session_start();
var_dump(session_gc(), file_exists("$outside/sess_a"));
?>
--CLEAN--
<?php
$base = __DIR__ . '/gc_dirdepth_symlink';
@unlink("$base/b/sess_b0");
@rmdir("$base/a") || @unlink("$base/a");
@rmdir("$base/b");
@rmdir($base);
@unlink("$base-outside/sess_a");
@rmdir("$base-outside");
?>
--EXPECT--
int(0)
bool(true)
Loading