From: Stephane Chazelas <stephane.chazelas@gmail.com>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: bug with $PWD in /
Date: Sat, 19 Sep 2015 20:28:51 +0100 [thread overview]
Message-ID: <20150919192850.GB6421@chaz.gmail.com> (raw)
In-Reply-To: <150919110800.ZM22888@torch.brasslantern.com>
2015-09-19 11:08:00 -0700, Bart Schaefer:
> On Sep 16, 5:26pm, Stephane Chazelas wrote:
> }
> } It looks like zsh has a similar issue as bash as reported at:
> } http://thread.gmane.org/gmane.comp.shells.bash.bugs/24162
>
> How about this?
>
> diff --git a/Src/utils.c b/Src/utils.c
> index 1de3d95..0016fa1 100644
> --- a/Src/utils.c
> +++ b/Src/utils.c
> @@ -692,9 +692,19 @@ ispwd(char *s)
> {
> struct stat sbuf, tbuf;
>
> - if (stat(unmeta(s), &sbuf) == 0 && stat(".", &tbuf) == 0)
> - if (sbuf.st_dev == tbuf.st_dev && sbuf.st_ino == tbuf.st_ino)
> - return 1;
> + if (stat((s = unmeta(s)), &sbuf) == 0 && stat(".", &tbuf) == 0)
> + if (sbuf.st_dev == tbuf.st_dev && sbuf.st_ino == tbuf.st_ino) {
> + /* POSIX: No element of $PWD may be "." or ".." */
[...]
Also, as mentioned on the bash thread:
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_05_03
SUSv4> PWD
SUSv4> Set by the shell and by the cd utility. In the shell the value
SUSv4> shall be initialized from the environment as follows. If a value
SUSv4> for PWD is passed to the shell in the environment when it is
SUSv4> executed, the value is an absolute pathname of the current working
SUSv4> directory that is no longer than {PATH_MAX} bytes including the
SUSv4> terminating null byte, and the value does not contain any
SUSv4> components that are dot or dot-dot, then the shell shall set PWD
SUSv4> to the value from the environment. Otherwise, if a value for PWD
SUSv4> is passed to the shell in the environment when it is executed, the
SUSv4> value is an absolute pathname of the current working directory,
SUSv4> and the value does not contain any components that are dot or
SUSv4> dot-dot, then it is unspecified whether the shell sets PWD to the
SUSv4> value from the environment or sets PWD to the pathname that would
SUSv4> be output by pwd -P. Otherwise, the sh utility sets PWD to the
SUSv4> pathname that would be output by pwd -P. In cases where PWD is set
SUSv4> to the value from the environment, the value can contain
SUSv4> components that refer to files of type symbolic link. In cases
SUSv4> where PWD is set to the pathname that would be output by pwd -P,
SUSv4> if there is insufficient permission on the current working
SUSv4> directory, or on any parent of that directory, to determine what
SUSv4> that pathname would be, the value of PWD is unspecified.
SUSv4> Assignments to this variable may be ignored. If an application
SUSv4> sets or unsets the value of PWD, the behaviors of the cd and pwd
SUSv4> utilities are unspecified.
So, the should recompute $PWD if the one it gets from the
environment is a relative path (it's not only about . or ..,
think of symlinks).
--
Stephane
next prev parent reply other threads:[~2015-09-19 19:28 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-16 16:26 Stephane Chazelas
2015-09-16 20:37 ` Bart Schaefer
2015-09-16 20:56 ` Bart Schaefer
2015-09-19 18:08 ` Bart Schaefer
2015-09-19 19:28 ` Stephane Chazelas [this message]
2015-09-19 20:47 ` Bart Schaefer
2015-09-28 18:13 ` Daniel Shahaf
2015-09-28 22:04 ` Bart Schaefer
2015-09-19 20:01 ` Peter Stephenson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150919192850.GB6421@chaz.gmail.com \
--to=stephane.chazelas@gmail.com \
--cc=schaefer@brasslantern.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).