Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: bug with $PWD in /



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



Messages sorted by: Reverse Date, Date, Thread, Author