From: Pixel Date: 2002-03-13T20:04:38+09:00 Subject: Re: Some potential RCRs "Guy N. Hurst" writes: > Bob Alexander wrote: > > > > On the topic of whether ".." and "." should be in our directory > > listings: > > [...] > > Can someone suggest an argument as to why having them in the listed > > entries is useful? > > I often use ls -al in the shell because I also need to see the > permissions and/or owner of '.' > And it is useful in the shell to use '..' as a navigation tool. be aware that most shells trick on you about '..' [1]: % mkdir -p dir1/dir2 % ln -s dir1/dir2 link1 % cd link1 % pwd /tmp/link1 % ls .. dir2 % (cd .. ; ls) dir1 % cd .. % pwd # should be /tmp/dir1 /tmp Another extreme argument against the use of ".." is [2]: # An insecure chdir("..") syscall is done after removing content of a # subdirectory in order to get back to the upper directory during recursive # removal of directory tree. # # Example of 'rm -fr /tmp/a' removing '/tmp/a/b/c' directory tree: # # (strace output simplified for better readability) # # chdir("/tmp/a") = 0 # chdir("b") = 0 # chdir("c") = 0 # chdir("..") = 0 # rmdir("c") = 0 # chdir("..") = 0 # rmdir("b") = 0 # fchdir(3) = 0 # rmdir("/tmp/a") = 0 # # After current directory is changed to /tmp/a/b/c a race condition occurs. # If we then move /tmp/a/b/c directory to the /tmp/c two subsequent # chdir("..") syscalls will move to the root directory / and rm will start # removing files from the whole file systems if it has enough privileges # (i.e. if called by root user). > But when I programmatically iterate over directory entries, > I don't care about '.' or '..' agreed. get rid of '.' and '..' !! [1] bash, zsh and pdksh do not really use chdir("..") when asked "cd .." tcsh, sash do really use chdir("..") when asked "cd .." [2] http://online.securityfocus.com/archive/1/260936