Bug in "ln" Applet

Alexander Griesser alexander.griesser at lkh-vil.or.at
Thu Apr 20 09:11:44 UTC 2006


Hi!

Today I found a bug in the ln applet (BB 1.0.2) with the "-f" option.

It is not possible, to overwrite a symbolic link to a directory with
a link to another directory.

For testing purposes, I created two files and two directories:

/tmp/bbtest $ touch file1 file2
/tmp/bbtest $ mkdir a b
/tmp/bbtest $ ls -l
drwxr-xr-x    2 tuxx     tuxx           40 Apr 20 11:01 a
drwxr-xr-x    2 tuxx     tuxx           40 Apr 20 11:01 b
-rw-r--r--    1 tuxx     tuxx            0 Apr 20 11:01 file1
-rw-r--r--    1 tuxx     tuxx            0 Apr 20 11:01 file2

Then I made a symlink called link1 to file1.
And afterwards I redirected the link to file2. That works fine.

/tmp/bbtest $ ln -s file1 link1
/tmp/bbtest $ ln -fs file2 link1
/tmp/bbtest $ ls -l
drwxr-xr-x    2 tuxx     tuxx           40 Apr 20 11:01 a
drwxr-xr-x    2 tuxx     tuxx           40 Apr 20 11:01 b
-rw-r--r--    1 tuxx     tuxx            0 Apr 20 11:01 file1
-rw-r--r--    1 tuxx     tuxx            0 Apr 20 11:01 file2
lrwxrwxrwx    1 tuxx     tuxx            5 Apr 20 11:01 link1 -> file2

If I don't use the -f option and try to redirect the link again
to file1, I get an error message. That's fine until here.

/tmp/bbtest $ ln -s file1 link1
ln: link1: File exists
/tmp/bbtest $ ln -s a link1
ln: link1: File exists

I now try to redirect this link to a directory, which also
works fine.

/tmp/bbtest $ ln -fs a link1
/tmp/bbtest $ ls -l
drwxr-xr-x    2 tuxx     tuxx           40 Apr 20 11:01 a
drwxr-xr-x    2 tuxx     tuxx           40 Apr 20 11:01 b
-rw-r--r--    1 tuxx     tuxx            0 Apr 20 11:01 file1
-rw-r--r--    1 tuxx     tuxx            0 Apr 20 11:01 file2
lrwxrwxrwx    1 tuxx     tuxx            1 Apr 20 11:02 link1 -> a

And now the strange behaviour starts. I do not get an error
message, when trying to redirect the link without the -f flag,
but at least it doesn't work.

/tmp/bbtest $ ln -s b link1
/tmp/bbtest $ ls -l
drwxr-xr-x    2 tuxx     tuxx           60 Apr 20 11:02 a
drwxr-xr-x    2 tuxx     tuxx           40 Apr 20 11:01 b
-rw-r--r--    1 tuxx     tuxx            0 Apr 20 11:01 file1
-rw-r--r--    1 tuxx     tuxx            0 Apr 20 11:01 file2
lrwxrwxrwx    1 tuxx     tuxx            1 Apr 20 11:02 link1 -> a

But now, with the -f parameter, it should work:

/tmp/bbtest $ ln -fs b link1
/tmp/bbtest $ ls -l
drwxr-xr-x    2 tuxx     tuxx           60 Apr 20 11:02 a
drwxr-xr-x    2 tuxx     tuxx           40 Apr 20 11:01 b
-rw-r--r--    1 tuxx     tuxx            0 Apr 20 11:01 file1
-rw-r--r--    1 tuxx     tuxx            0 Apr 20 11:01 file2
lrwxrwxrwx    1 tuxx     tuxx            1 Apr 20 11:02 link1 -> a
/tmp/bbtest $

Unfortunately, it doesn't.
I had a look at the ln.c sourcecode, but at the first glance didn't
find any hints about why it works with files and not with directories...

regards,
-- 
Alexander Griesser (Netzwerkadministration)
E-Mail: alexander.griesser at lkh-vil.or.at | Web: http://www.lkh-vil.or.at
KABEG LKH Villach | Nikolaigasse 43 | 9500 Villach
Tel.:   +43 4242 208 3061 | Fax.:   +43 4242 971 3061



More information about the busybox mailing list