Bug 510809 - readlink cannot handle recursive symlinks
readlink cannot handle recursive symlinks
Status: CLOSED ERRATA
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: coreutils (Show other bugs)
5.3
All Linux
urgent Severity urgent
: rc
: ---
Assigned To: Ondrej Vasik
qe-baseos-daemons
: ZStream
Depends On:
Blocks: 567545
  Show dependency treegraph
 
Reported: 2009-07-10 17:15 EDT by Jeff Bastian
Modified: 2011-07-21 08:10 EDT (History)
6 users (show)

See Also:
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.
Story Points: ---
Clone Of:
Environment:
Last Closed: 2011-07-21 06:33:50 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


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

  None (edit)
Description Jeff Bastian 2009-07-10 17:15:15 EDT
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 17:19:03 EDT
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 Product and Program Management 2009-11-06 13:49:57 EST
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 10:33:02 EST
pm_ack for RHEL 5.4.z.
Comment 14 Kamil Dudka 2010-02-22 11:48:25 EST
(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 09:35:34 EDT
    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 08:07:38 EDT
    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 06:33:50 EDT
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 08:10:24 EDT
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.