Bug 510809 - readlink cannot handle recursive symlinks
Summary: readlink cannot handle recursive symlinks
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: coreutils
Version: 5.3
Hardware: All
OS: Linux
urgent
urgent
Target Milestone: rc
: ---
Assignee: Ondrej Vasik
QA Contact: qe-baseos-daemons
URL:
Whiteboard:
Depends On:
Blocks: 567545
TreeView+ depends on / blocked
 
Reported: 2009-07-10 21:15 UTC by Jeff Bastian
Modified: 2018-10-27 13:48 UTC (History)
6 users (show)

Fixed In Version: coreutils-5.97-25.el5
Doc Type: Bug Fix
Doc Text:
When a directory contained a symbolic link to itself, the readlink command incorrectly gave the following error message: "Too many levels of symbolic links". With this update, the readlink command is able to correctly resolve values of recursive symbolic links to directories and no error messages are given.
Clone Of:
Environment:
Last Closed: 2011-07-21 10:33:50 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)
patch to fix readlink (10.65 KB, patch)
2009-07-10 21:19 UTC, Jeff Bastian
no flags Details | Diff


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2011:1074 0 normal SHIPPED_LIVE coreutils bug fix and enhancement update 2011-07-21 10:33:32 UTC

Description Jeff Bastian 2009-07-10 21:15:15 UTC
Description of problem:
The readlink command fails with an error "Too many levels of symbolic links", even if there are only 2 levels.

The readlink command from RHEL 3 and RHEL 4 and from Fedora 11 all work fine.

Among other changes between RHEL 4 and RHEL 5, RHEL 5's coreutils added calls to cycle_check() in lib/canonicalize.c, but in upstream canonicalize.c (now in gnulib instead of coreutils), we see the comment:
          /* Detect loops.  We cannot use the cycle-check module here,
             since it's actually possible to encounter the same symlink
             more than once in a given traversal.  However, encountering
             the same symlink,NAME pair twice does indicate a loop.  */

http://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=blob;f=lib/canonicalize.c;h=4f348398fd69ae516396313d18ac294a4ca3dde3;hb=b653eda3ac4864de205419d9f41eec267cb89eeb#l262

The latest canonicalize.c uses seen_triple() instead of cycle_check().


Version-Release number of selected component (if applicable):
coreutils-5.97-19.el5

How reproducible:
every time

Steps to Reproduce:
1. Create a directory with a symlink to itself
       mkdir /tmp/dir
       cd /tmp/dir
       ln -s ../dir dirlink

2. Run readlink using the 'dirlink' symlink recursively
       readlink -v -f dirlink
       readlink -v -f dirlink/dirlink
       readlink -v -f dirlink/dirlink/dirlink
  
Actual results:
The first readlink command on just dirlink succeeds, but the 2nd and 3rd commands fail with 
   readlink: dirlink/dirlink: Too many levels of symbolic links

Expected results:
$ readlink -v -f dirlink
/tmp/dir
$ readlink -v -f dirlink/dirlink
/tmp/dir
$ readlink -v -f dirlink/dirlink/dirlink
/tmp/dir


Additional info:

Comment 1 Jeff Bastian 2009-07-10 21:19:03 UTC
Created attachment 351304 [details]
patch to fix readlink

I've backported the changes from upstream to use seen_triple() instead of cycle_check().

Comment 5 RHEL Program Management 2009-11-06 18:49:57 UTC
This request was evaluated by Red Hat Product Management for
inclusion, but this component is not scheduled to be updated in
the current Red Hat Enterprise Linux release. If you would like
this request to be reviewed for the next minor release, ask your
support representative to set the next rhel-x.y flag to "?".

Comment 12 Ludek Smid 2010-02-22 15:33:02 UTC
pm_ack for RHEL 5.4.z.

Comment 14 Kamil Dudka 2010-02-22 16:48:25 UTC
(In reply to comment #1)
> Created an attachment (id=351304) [details]
> patch to fix readlink

The patch looks good and solves the problem for me.

Comment 19 Ondrej Vasik 2011-03-31 13:35:34 UTC
    Technical note added. If any revisions are required, please edit the "Technical Notes" field
    accordingly. All revisions will be proofread by the Engineering Content Services team.
    
    New Contents:
When a directory contained a symbolic link to itself, the readlink command incorrectly gave the following error message when attempting to read the value of the symbolic link : "Too many levels of symbolic links". With this update, readlink is once again able to correctly resolve the value of the recursive symbolic links to containing directories, or "directory loops".

Comment 22 Tomas Capek 2011-07-13 12:07:38 UTC
    Technical note updated. If any revisions are required, please edit the "Technical Notes" field
    accordingly. All revisions will be proofread by the Engineering Content Services team.
    
    Diffed Contents:
@@ -1 +1 @@
-When a directory contained a symbolic link to itself, the readlink command incorrectly gave the following error message when attempting to read the value of the symbolic link : "Too many levels of symbolic links". With this update, readlink is once again able to correctly resolve the value of the recursive symbolic links to containing directories, or "directory loops".+When a directory contained a symbolic link to itself, the readlink command incorrectly gave the following error message: "Too many levels of symbolic links". With this update, the readlink command is able to correctly resolve values of recursive symbolic links to directories and no error messages are given.

Comment 23 errata-xmlrpc 2011-07-21 10:33:50 UTC
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHBA-2011-1074.html

Comment 24 errata-xmlrpc 2011-07-21 12:10:24 UTC
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHBA-2011-1074.html


Note You need to log in before you can comment on or make changes to this bug.