|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-11-04 02:00 UTC] j at pureftpd dot org
[2006-11-04 12:33 UTC] j at pureftpd dot org
[2007-01-22 09:36 UTC] dmitry@php.net
[2007-02-09 07:50 UTC] j at pureftpd dot org
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 02:00:01 2025 UTC |
Description: ------------ realpath() on a symlink returns the final file the link points to. Caching symbolic links through the realpath cache can cause unexpected behaviors. Here's a fix against PHP 5.2.0 --- TSRM/tsrm_virtual_cwd.c.orig Sat Nov 4 00:56:05 2006 +++ TSRM/tsrm_virtual_cwd.c Sat Nov 4 00:58:03 2006 @@ -562,7 +562,11 @@ } if (use_realpath && CWDG(realpath_cache_size_limit)) { - realpath_cache_add(path, path_length, state- >cwd, state->cwd_length, t TSRMLS_CC); + struct stat buf; + + if (lstat(path, &buf) == 0 && !S_ISLNK (buf.st_mode)) { + realpath_cache_add(path, path_length, state->cwd, state- >cwd_length, t TSRMLS_CC); + } } if (verify_path && verify_path(state)) { Reproduce code: --------------- See bug #36555, or that code : <?php @unlink('/tmp/1link'); @unlink('/tmp/1tmp'); @unlink('/tmp/testfile1'); file_put_contents('/tmp/testfile1', '42'); symlink('/tmp/testfile1', '/tmp/1tmp'); rename('/tmp/1tmp', '/tmp/1link'); $a = file_get_contents('/tmp/1link'); var_dump($a); unlink('/tmp/1link'); clearstatcache(); $a = file_get_contents('/tmp/1link'); var_dump($a); ?> Expected result: ---------------- The second file_get_contents() should fail because /tmp/1link has been unlinked. But it doesn't. Actual result: -------------- 42 42