Re: Possible bug in readlink, canonicalize fails.

2007-09-21 Thread Jim Meyering
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


Re: Possible bug in readlink, canonicalize fails.

2007-09-21 Thread Andreas Schwab
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.

2007-09-21 Thread Dmitry V. Levin
Hi,

On Fri, Sep 21, 2007 at 12:42:36AM -0700, mpb 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.
[...]
> path=/tmp/c0/b3/b4/a5/a6
[...]
> readlink -e $path

$ readlink -ev /tmp/c0/b3/b4/a5/a6
readlink: /tmp/c0/b3/b4/a5/a6: Too many levels of symbolic links
$ readlink -ev /tmp/c0/b3/b4/a5
readlink: /tmp/c0/b3/b4/a5: Too many levels of symbolic links

$ strace -e lstat64 stat -c '' /tmp/c0/b3/b4/a5/a6
lstat64("/tmp/c0/b3/b4/a5/a6", {st_mode=S_IFREG|0644, st_size=9, ...}) = 0
$ strace -e lstat64,readlink readlink -e /tmp/c0/b3/b4/a5/a6
lstat64("/tmp", {st_mode=S_IFDIR|S_ISVTX|0777, st_size=4096, ...}) = 0
lstat64("/tmp/c0", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat64("/tmp/c0/b3", {st_mode=S_IFLNK|0777, st_size=13, ...}) = 0
readlink("/tmp/c0/b3", "/tmp/a0/a2/b3", 14) = 13
lstat64("/tmp", {st_mode=S_IFDIR|S_ISVTX|0777, st_size=4096, ...}) = 0
lstat64("/tmp/a0", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat64("/tmp/a0/a2", {st_mode=S_IFLNK|0777, st_size=5, ...}) = 0
readlink("/tmp/a0/a2", "a1/a2", 6)  = 5
lstat64("/tmp/a0/a1", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat64("/tmp/a0/a1/a2", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat64("/tmp/a0/a1/a2/b3", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat64("/tmp/a0/a1/a2/b3/b4", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat64("/tmp/a0/a1/a2/b3/b4/a5", {st_mode=S_IFLNK|0777, st_size=19, ...}) = 0
readlink("/tmp/a0/a1/a2/b3/b4/a5", "/tmp/a0/a2/a3/a4/a5", 20) = 19
lstat64("/tmp", {st_mode=S_IFDIR|S_ISVTX|0777, st_size=4096, ...}) = 0
lstat64("/tmp/a0", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat64("/tmp/a0/a2", {st_mode=S_IFLNK|0777, st_size=5, ...}) = 0

That is, /tmp/a0/a2 is checked twice, and cycle_check() aborts the
traversal.


-- 
ldv


pgpIjTi4ntcB6.pgp
Description: PGP signature
___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils


Possible bug in readlink, canonicalize fails.

2007-09-21 Thread mpb
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 .
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