Possible bug in readlink, canonicalize fails.
Hi, I believe the following script demonstrates that readlink cannot always canonicalize paths. It may be possible to create a simpler demonstration of the bug, but I could not trivially do so. Thanks! -mpb -- #! /bin/bash # Clean up previous demonstations of the bug. if [ -a /tmp/a0 ]; then rm -r /tmp/a0; fi if [ -a /tmp/c0 ]; then rm -r /tmp/c0; fi # Create 3 directories. mkdir -p /tmp/a0/a1/a2/a3/a4/a5 mkdir -p /tmp/a0/a1/a2/b3/b4 mkdir -p /tmp/c0 # Create 1 file. echo 'I am a6.' /tmp/a0/a1/a2/a3/a4/a5/a6 # Create 3 symbolic links inside those directories. ln -s a1/a2 /tmp/a0/a2 ln -s /tmp/a0/a2/b3 /tmp/c0/b3 ln -s /tmp/a0/a2/a3/a4/a5 /tmp/c0/b3/b4/a5 # Show what we have created. find /tmp/a0 /tmp/c0 # Specify a convoluted (but valid) path to the file a6. path=/tmp/c0/b3/b4/a5/a6 # Look! The file exists at $path! echo echo The file exists ... ls -l $path cat $path # But readlink cannot canonicalize it! echo echo ... but readlink cannot canonicalize it! readlink -f $path echo readlink exit status: $? readlink -e $path echo readlink exit status: $? readlink -m $path echo readlink exit status: $? # I am running: readlink (GNU coreutils) 6.9 echo readlink --version -- When I run the script, I get the following output: $ bash bug.sh /tmp/a0 /tmp/a0/a1 /tmp/a0/a1/a2 /tmp/a0/a1/a2/a3 /tmp/a0/a1/a2/a3/a4 /tmp/a0/a1/a2/a3/a4/a5 /tmp/a0/a1/a2/a3/a4/a5/a6 /tmp/a0/a1/a2/b3 /tmp/a0/a1/a2/b3/b4 /tmp/a0/a1/a2/b3/b4/a5 /tmp/a0/a2 /tmp/c0 /tmp/c0/b3 The file exists ... -rw-r--r-- 1 asterisk asterisk 9 Sep 21 00:39 /tmp/c0/b3/b4/a5/a6 I am a6. ... but readlink cannot canonicalize it! readlink exit status: 1 readlink exit status: 1 /tmp/a0/a2/a3/a4/a5/a6 readlink exit status: 0 readlink (GNU coreutils) 6.9 Copyright (C) 2007 Free Software Foundation, Inc. This is free software. You may redistribute copies of it under the terms of the GNU General Public License http://www.gnu.org/licenses/gpl.html. There is NO WARRANTY, to the extent permitted by law. Written by Dmitry V. Levin. ___ Bug-coreutils mailing list Bug-coreutils@gnu.org http://lists.gnu.org/mailman/listinfo/bug-coreutils
Re: Possible bug in readlink, canonicalize fails.
mpb [EMAIL PROTECTED] writes: # Create 3 symbolic links inside those directories. ln -s a1/a2 /tmp/a0/a2 ln -s /tmp/a0/a2/b3 /tmp/c0/b3 ln -s /tmp/a0/a2/a3/a4/a5 /tmp/c0/b3/b4/a5 The problem is that we are crossing the /tmp/a0/a2 symlink twice, so canonicalize_filename_mode thinks this is a loop. But in fact the reference comes from different symlink expansions, and the second one uses a different way through the filesystem. Due to the way cycle_check works this testcase only works when the offending symlink is the second, fourth, eighth, ... one encountered. The kernel can cope because it only errors out after a fixed number of symlink expansions, independent of the actual nodes crossed. Andreas. -- Andreas Schwab, SuSE Labs, [EMAIL PROTECTED] SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany PGP key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 And now for something completely different. ___ Bug-coreutils mailing list Bug-coreutils@gnu.org http://lists.gnu.org/mailman/listinfo/bug-coreutils
Re: Possible bug in readlink, canonicalize fails.
mpb [EMAIL PROTECTED] wrote: I believe the following script demonstrates that readlink cannot always canonicalize paths. It may be possible to create a simpler demonstration of the bug, but I could not trivially do so. Thanks for the report and the nice test case. I have code that's a work in progress (needed in another part of coreutils) that does a better job of detecting such (non)cycles. This will be fixed before 6.10. ___ Bug-coreutils mailing list Bug-coreutils@gnu.org http://lists.gnu.org/mailman/listinfo/bug-coreutils