|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66497 symlink improperly creates recursive link on existing symlink without a target
Submitted: 2014-01-16 15:18 UTC Modified: -
Avg. Score:3.7 ± 0.9
Reproduced:3 of 3 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: mattsch at gmail dot com Assigned:
Status: Open Package: Filesystem function related
PHP Version: 5.5.8 OS: Gentoo Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2014-01-16 15:18 UTC] mattsch at gmail dot com
symlink improperly creates a recursive link on existing symlink without a target.  This appears to be a regression since php 5.2 which was broken in php 5.3 and all subsequent versions.  In php 5.2, calling symlink on an existing symlink always failed regardless whether the target existed.

Test script:
Make symlink create a symbolic link that does not link to anything (link does not exist)
symlink('43', '0'); // Result: 0 -> 43

// second call to the same thing
symlink('43', '0'); // Result: 43 -> 43

third call will fail with a warning:

PHP Warning:  symlink(): No such file or directory in test.php on line 2
symlink('43', '0'); 

Expected result:
symlink should fail and emit a warning after the second call to a non-existing link and not create a recursive link on the target.

Actual result:
symlink fails on the third call to create a symlink that already exists after creating a recursive symlink to the target.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-01-07 14:24 UTC] rainer-phpbugs at 7val dot com
I just stumbled over the same problem on Ubuntu 14.10 and a current Linux Mint. Note that ln behaves differently:

/tmp/foo $ ls -l /tmp/foo/
lrwxrwxrwx 1 alex alex  4 Jan  7 12:58 testjobs -> jobs

/tmp/foo $ ln -s /tmp/foo/jobs /tmp/foo/testjobs 
ln: failed to create symbolic link '/tmp/foo/testjobs': File exists

/tmp/foo $ php -r "symlink('/tmp/foo/jobs', '/tmp/foo/testjobs');"
/tmp/foo $ ls -l /tmp/foo/
lrwxrwxrwx 1 alex alex 13 Jan  7 13:21 jobs -> /tmp/foo/jobs
lrwxrwxrwx 1 alex alex  4 Jan  7 12:58 testjobs -> jobs

/tmp/foo $ cat jobs 
cat: jobs: Too many levels of symbolic links
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Fri Dec 09 23:05:55 2022 UTC