On 31/03/2023 15:46, Denys Vlasenko wrote:
cd DIR
does the foillowing: cdcmd() -> docd() -> updatepwd(), and updatepwd
has the code which "normalizes" the DIR: prepends current dir if DIR
is not absolute, then eliminates "SUBDIR/.." sections.
The bug is, it does not care whether SUBDIR exists.
cd BOGUSDIR/..
always works - it chdir's into current directory.
Indeed, POSIX says that '..' should only remove the previous path
component if the previous path component refers to a directory, so this
behaviour is in conflict, and most (not all) other shells issue the
error you expect.
Note though that the normalisation is also part of the spec for 'cd -L'
(the default): if we have
a/
a/b/
c -> a/b
then
cd c/..
is supposed to be valid and return you to the current directory, despite
c/.. referring to a. To go into a using c/.., cd -P c/.. is needed.
A corner case is what to do when '.' does not refer to a directory, as in
mkdir a
cd a
rmdir ../a
cd ..
By the same logic, this should result in an error as well. Most shells
don't report anything. bash does in POSIX mode, in accordance with the
spec, but does not report anything in its default mode. There may be
unexpected fallout if this too is made a hard error in dash.
Cheers,
Harald van Dijk