Bug #66497 [Com]: symlink improperly creates recursive link on existing symlink without a target
| From: | rainer-phpbugs at 7val dot com | Date: | Wed, 07 Jan 2015 14:24:12 +0000 |
| Subject: | Bug #66497 [Com]: symlink improperly creates recursive link on existing symlink without a target | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-189700@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=66497&edit=1
ID: 66497
Comment by: rainer-phpbugs at 7val dot com
Reported by: mattsch at gmail dot com
Summary: symlink improperly creates recursive link on
existing symlink without a target
Status: Open
Type: Bug
Package: Filesystem function related
Operating System: Gentoo Linux
PHP Version: 5.5.8
Block user comment: N
Private report: N
New Comment:
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
Previous Comments:
------------------------------------------------------------------------
[2014-01-16 15:18:47] 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.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=66497&edit=1