Menu

#50 CRTL bug in lstat causes bugs in ls and rm commands.

coreutils 8.21
closed-fixed
nobody
3
2014-01-14
2012-12-20
No

I have come across another bug in the OpenVMS CRTL implementation of lstat during the course of testing the new version of bash 4.2.39 with the m4-1.4.16 configure script. During the course of executing the configure script for m4-1.4.16, a test directory is created in which a self referencing symbolic link file is created. Although the symbolic link file is created successfully, later, when the configure script attempts to remove the test directory and its contents, the configure script elicits an error indicating that the test directory is not empty. After building the source code for the GNV rm command in debug and re-running the configure script, I discovered that the reason for this error is caused by non-conformant behavior of the lstat function when processing self-referencing symbolic link files.

If a self-referencing symbolic link file is created in a directory, attempts to list the contents of the directory in which it was created (using the ls command) or delete the directory in which it was created (using the rm -rf command), return an error indicating that the file does not exist. These errors are a result of a bug in the lstat function. According to the documentation for lstat, when the target file is a symbolic link file, lstat is supposed to return the information with respect to the symbolic link file itself. But, when the symbolic link file is self-referencing, the OpenVMS implementation of lstat returns -1 and sets errno to ENOENT. This behavior causes the ls and rm commands to give the false indication that the file does not exist. This error does NOT occur if the symbolic link file refers to a file other than itself.

What follows is the same command sequence that elicits the bug performed first on an OpenVMS machine which fails and then on an Open SUSE64 Linux machine which succeeds:

$ bash
ROBERTSON@iqdev1:~ > bash --version
GNU bash, version 4.2.39(1)-release (alpha-dec-vms)
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
GNV-3.0-1-JEM-1 Dec 3 2012 13:55:06
ROBERTSON@iqdev1:~ > mkdir ewrtest
ROBERTSON@iqdev1:~ > cd ewrtest
ROBERTSON@iqdev1:~/ewrtest > ln -s test.file test.file
ROBERTSON@iqdev1:~/ewrtest > DCL DIR/FULL

Directory DISK_USERS:[PSX_ROOT.usr.robertson.ewrtest]

test.file;1 File ID: (174339,4,0)
Size: 1/16 Owner: [ENGINEERING,ROBERTSON]
Created: 17-DEC-2012 12:55:28.90
Revised: 17-DEC-2012 12:55:28.98 (1)
Expires: <None specified>
Backup: <No backup recorded>
Effective: <None specified>
Recording: <None specified>
Accessed: 17-DEC-2012 12:55:28.94
Attributes: 17-DEC-2012 12:55:28.98
Modified: 17-DEC-2012 12:55:28.96
Linkcount: 1
File organization: Special: symbolic link
Link Contents: test.file
Shelved state: Online
Caching attribute: Writethrough
File attributes: Allocation: 16, Extend: 0, Global buffer count: 0, No version limit
RMS attributes: None
Journaling enabled: None
File protection: System:RWED, Owner:RWED, Group:RE, World:
Access Cntrl List: None
Client attributes: None

Total of 1 file, 1/16 blocks.
ROBERTSON@iqdev1:~/ewrtest > ls -l
ls: test.file: no such file or directory
total 0
ROBERTSON@iqdev1:~/ewrtest > cd ..
ROBERTSON@iqdev1:~ > rm -rf ewrtest
rm: cannot remove directory `ewrtest': directory not empty
ROBERTSON@iqdev1:~ > exit
exit
$ ssh "ewr@suse64.iqware.us"
ewr's password:
Authentication successful.

Last login: Mon Dec 17 12:33:18 2012 from office-3.iqware.us
Have a lot of fun...
ewr@suse64:~> bash --version
GNU bash, version 3.1.17(1)-release (x86_64-suse-linux)
Copyright (C) 2005 Free Software Foundation, Inc.
ewr@suse64:~> mkdir ewrtest
ewr@suse64:~> cd ewrtest
ewr@suse64:~/ewrtest> ln -s test.file test.file
ewr@suse64:~/ewrtest> ls -l
total 0
lrwxrwxrwx 1 ewr dev 9 2012-12-17 12:57 test.file -> test.file
ewr@suse64:~/ewrtest> cd ..
ewr@suse64:~> rm -rf ewrtest
ewr@suse64:~> exit
logout

Connection to suse64.iqware.us closed.

$

Discussion

  • John Malmberg

    John Malmberg - 2013-09-19

    I have reproduced this issue in the coreutils 8.21 port and will investigate.

     
  • John Malmberg

    John Malmberg - 2013-09-22

    I have tested lstat() on VMS 8.4 Alpha and Integrity, and VMS 8.3 Alpha.

    In all cases, lstat() and stat() are returning identical information.

    In addition the decc$to_vms() routine is failing to return a VMS filename when the Unix path is to a dangling symbolic link.

    With the decc$to_vms() routine failing, it will require writing a UNIX_TO_VMS translation routine to work around this.

    The only other workaround would be to modify coreutils to report that VMS can not create symbolic links.

     
  • John Malmberg

    John Malmberg - 2014-01-14
    • status: open --> closed-fixed
    • Group: coreutils --> coreutils 8.21
     
Monday.com Logo