Bug 510809

Summary: readlink cannot handle recursive symlinks
Product: Red Hat Enterprise Linux 5 Reporter: Jeff Bastian <jbastian>
Component: coreutilsAssignee: Ondrej Vasik <ovasik>
Status: CLOSED ERRATA QA Contact: qe-baseos-daemons
Severity: urgent Docs Contact:
Priority: urgent    
Version: 5.3CC: asersen, jscotka, jwest, kdudka, syeghiay, tao
Target Milestone: rcKeywords: ZStream
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
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 10:33:50 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 567545    
Attachments:
Description Flags
patch to fix readlink none

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