LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Is this a bug? (BASH and Z shells) (https://www.linuxquestions.org/questions/linux-software-2/is-this-a-bug-bash-and-z-shells-230488/)

KingofBLASH 09-14-2004 10:25 AM

Is this a bug? (BASH and Z shells)
 
Do the following as an underpriviledged user in the bash shell:

Code:

mkdir foo
cd foo
su
cd ..
rm -fR ./foo
exit
pwd

Under the BASH shell and Z shell I get:
./foo (the directory)

Under tsch, and csh I get:
/usr/bin/ls: foo: No such file or directory

I assume this is a bug in the BASH and Z shells, and tsch and csh handle pwd correctly.

But, I know that you can open a file, delete the file, and have access to an anonymous file (because no inode refers to your inode, or something)

So have I found a bug, or just a peculiar feature of *nix? And is it worth bothering the maintainers of BASH and Z shell about?

druuna 09-14-2004 11:30 AM

The pwd used in bash is a built-in, the pwd used with (t)csh is the 'real' pwd, there's no pwd built-in in (t)csh.

Try the above, but use /bin/pwd instead of pwd.

I do agree that it's strange the the two are not giving the same output. Cannot find a reason for that, but it must be done with something in mind.

KingofBLASH 09-14-2004 12:19 PM

Do you think that I should report it? It seems to me like BASH (or any of the shells) should check when coming back from a su whether or not the directory still exists... I have been thinking about some possible ways to exploit it as a security vulnerability, but I am not smart enough. :-D But still, it seems like it should check....

druuna 09-14-2004 01:04 PM

I don't think it's a bug, but implemented this way with something in mind (still trying to find out what). It is (kinda) known, this from man pwd:

DESCRIPTION
NOTE: your shell may have its own version of pwd which will supercede
the version described here. Please refer to your shell's documentation
for details about the options it supports.


It doesn't say that much, but you are warned that other pwd's (builtins or otherwise) might behave different.

Something that just came to mind:

When executing pwd you are asking for the present working directory, with that in mind:

You could argue that, since you are still in the foo dir, that it is the current working directory. That it is impossible to do (some) things because in reality it doesn't excist anymore could be considered as 'beside the point'.

Personally I can see the logic in that, but feel free to diragree ;)

mikshaw 09-14-2004 06:14 PM

I agree with Druuna, though it's only my opinion, and not necessarily the way bash was written.

As far as your user is concerned, you entered foo and never left it....so logically you're still there. You didn't go anywhere else, and you can't be nowhere, so you have to be in foo.


All times are GMT -5. The time now is 09:13 PM.