From: j at pureftpd dot org Operating system: Any PHP version: 5.2.0 PHP Bug Type: Filesystem function related Bug description: symbolic links should not be inserted into the realpath cache
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 -- Edit bug report at http://bugs.php.net/?id=39367&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=39367&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=39367&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=39367&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=39367&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=39367&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=39367&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=39367&r=needscript Try newer version: http://bugs.php.net/fix.php?id=39367&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=39367&r=support Expected behavior: http://bugs.php.net/fix.php?id=39367&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=39367&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=39367&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=39367&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=39367&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=39367&r=dst IIS Stability: http://bugs.php.net/fix.php?id=39367&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=39367&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=39367&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=39367&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=39367&r=mysqlcfg