bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

GNU bash, 3.00.15(1)-release, referenced cmd in cwd executes alternate c


From: Bojan Land
Subject: GNU bash, 3.00.15(1)-release, referenced cmd in cwd executes alternate cmd
Date: Tue, 02 Jan 2007 02:28:27 -0500

GNU bash, version 3.00.15(1)-release (i686-redhat-linux-gnu)
Is what I am describing a bug, or lack of understanding?

There are three examples here.  If executable file is in cwd and path
points to cwd and if the same file is referenced bash executes a file
that is outside of the cwd!  This to me seems quite dangerous, though I
realize it could just be my inexperience with bash.

BASHBUG0, simple problem recreation
BASHBUG1, actual problem encountered
BASHBUG2, unexplained situation

Distro: CentOS 4.2
Currently doesn't have yum update available



BASHBUG0: command referenced is not command executed
BUGDESC: when command to be executed is in current path and cwd
alternate cmd executed instead.

[user@host bin]$ pwd
/home/user/bin
[user@host bin]$ ls
file1  file2  file3  mycmd  file4 
[user@host bin]$ which mycmd
/bin/mycmd
[user@host bin]$ mycmd
hello me
[user@host bin]$ ./mycmd
hello me
[user@host bin]$ /bin/mycmd
hello you
[user@host bin]$ cat /bin/mycmd
#!/bin/sh

echo "hello you"
[user@host bin]$ cat ./mycmd
#!/bin/sh

echo "hello me"
[user@host Desktop]$ sh --version
GNU bash, version 3.00.15(1)-release (i686-redhat-linux-gnu)
Copyright (C) 2004 Free Software Foundation, Inc.




BASHBUG1: path command selection
BUGDESC: command referenced is not command executed.  Reference from
man:
       An attempt is first made to
       open the file in the current directory, and, if no file is found,
then
       the shell searches the directories in PATH for the script.

[root@host sbin]# pwd
/usr/local/sbin
[root@host sbin]# ls
useradd  useraddextra  userdel  userdelextra  userextra.fi
[root@host sbin]# which userdel
/usr/local/sbin/userdel
[root@host sbin]# userdel
usage: userdel [-r] name
[root@host sbin]# ./userdel
here
Remove local extras (y to confirm)? No.
usage: userdel [-r] name
[root@host sbin]# userdel
usage: userdel [-r] name
[root@host sbin]# ./userdel
here
Remove local extras (y to confirm)? No.
usage: userdel [-r] name
[root@host sbin]# echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin



BASHBUG2: description or implementation of option P
BUGDESC: When P is unset the symlink is still followed, though PS not
updated.
        Reference from man:
              -P      If  set,  the shell does not follow symbolic links
when
                      executing commands such as cd that change  the
current
                      working  directory.   It  uses  the  physical
directory
                      structure instead.  By default, bash follows the
logi-
                      cal chain of directories when performing commands
which
                      change the current directory.


[root@host user]# pwd
/home/user
[root@host user]# ls -l
total 88
drwxrwxr-x  3 user users 4096 Jan  2 00:59 bin
drwxrwxr-x  2 user users 4096 Jan  1 06:22 dir2
drwxr-xr-x  4 user users 4096 Jan  2 01:05 dir3
-rw-rw-r--  1 user users 7522 Nov 19 21:08 file1
drwxr-xr-x  2 user users 4096 Jan  1 04:48 dir4
-rw-------  1 user users   46 Nov 17 14:20 file2
drwxrwxr--  2 user users 4096 Nov 23 19:35 dir5
drwxrwxr-x  9 user users 4096 Jan  1 05:13 dir6
lrwxrwxrwx  1 root root    24 Nov  4  2005 public_html -
> /var/www/html_users/user
drwxr-xr-x  2 user users 4096 Jan 30  2000 dir7
drwxrwxr-x  3 user users 4096 Dec 31 02:43 dir8
[root@host user]# set -P
[root@host user]# cd public_html
[root@host user]# pwd
/var/www/html_users/user
[root@host user]# cd /home/user
[root@host user]# set +P
[root@host user]# cd public_html
[root@host public_html]# pwd
/home/user/public_html
[root@host public_html]#





reply via email to

[Prev in Thread] Current Thread [Next in Thread]