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.

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

echo "hello you"
address@hidden bin]$ cat ./mycmd
#!/bin/sh

echo "hello me"
address@hidden 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.

address@hidden sbin]# pwd
/usr/local/sbin
address@hidden sbin]# ls
useradd  useraddextra  userdel  userdelextra  userextra.fi
address@hidden sbin]# which userdel
/usr/local/sbin/userdel
address@hidden sbin]# userdel
usage: userdel [-r] name
address@hidden sbin]# ./userdel
here
Remove local extras (y to confirm)? No.
usage: userdel [-r] name
address@hidden sbin]# userdel
usage: userdel [-r] name
address@hidden sbin]# ./userdel
here
Remove local extras (y to confirm)? No.
usage: userdel [-r] name
address@hidden 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.


address@hidden user]# pwd
/home/user
address@hidden 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
address@hidden user]# set -P
address@hidden user]# cd public_html
address@hidden user]# pwd
/var/www/html_users/user
address@hidden user]# cd /home/user
address@hidden user]# set +P
address@hidden user]# cd public_html
address@hidden public_html]# pwd
/home/user/public_html
address@hidden public_html]#





reply via email to

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