php.net |  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: -
Votes:3
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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mattsch at gmail dot com
New email:
PHP Version: OS:

 

 [2014-01-16 15:18 UTC] mattsch at gmail dot com
Description:
------------
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:
---------------
<?php
/* 
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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 17:01:30 2024 UTC