From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27275 invoked by alias); 19 Sep 2015 20:47:45 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 36562 Received: (qmail 12144 invoked from network); 19 Sep 2015 20:47:44 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.0 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:message-id:date:in-reply-to:comments :references:to:subject:mime-version:content-type; bh=Ek2X+imPp8mev3Mu3kPbv2XHYXBiDFsRjFWyTzKgLEA=; b=UJBqOjeNVTaj1aGfQM7Tq3M9hF6k6lkE9Mz46sQ7UTL9Ib9MVi3EbhkE/ZqgLtNmkS eGVaPYEBX4NbwjWnLYpOBg8yXO1QQZeFYnOlhjGDsKBMqqByjKndYqskWO97B6H7P0MO BtiP7rhENf9QbsTanesNzF0Yc/pfF7SsgHBMWSTYXGfm4tqfQYBU78GTiGfC1SDKGh94 jcpGjfl1cMJWadCgiAhk/SCaMOc1Jtt8AGW9wFMec58o4ix5D9hQ7l0+29H/NuJH4fBo xf4JHW3zomC9iBmGdQDIUQpwhdoqY65h5gwSMkYnprEKFNVN+Uwn3OW/FLkTTK84MvbQ MeHA== X-Gm-Message-State: ALoCoQkHfz9HqNVkPg0/P38gw2eEUwqH93gRAZA94k5ZgYET9kTTqo9RpZadO2H87VhhckoW5Vdb X-Received: by 10.60.128.130 with SMTP id no2mr7752435oeb.47.1442695662838; Sat, 19 Sep 2015 13:47:42 -0700 (PDT) From: Bart Schaefer Message-Id: <150919134740.ZM23592@torch.brasslantern.com> Date: Sat, 19 Sep 2015 13:47:40 -0700 In-Reply-To: <20150919192850.GB6421@chaz.gmail.com> Comments: In reply to Stephane Chazelas "Re: bug with $PWD in /" (Sep 19, 8:28pm) References: <20150916162630.GA6436@chaz.gmail.com> <150919110800.ZM22888@torch.brasslantern.com> <20150919192850.GB6421@chaz.gmail.com> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: Zsh hackers list Subject: Re: bug with $PWD in / MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Sep 19, 8:28pm, Stephane Chazelas wrote: } Subject: Re: bug with $PWD in / } } 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). It'd have to be a symlink from the current directory to itself, tho. Other symbolic links are explicitly permitted by the text you quoted. This replaces the previous patch, although it's 90% the same. diff --git a/Src/utils.c b/Src/utils.c index 1de3d95..ab3b0c2 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -692,9 +692,23 @@ 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; + /* POSIX: environment PWD must be absolute */ + if (*s != '/') + return 0; + + 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 ".." */ + while (*s) { + if (s[0] == '.' && + (!s[1] || s[1] == '/' || + (s[1] == '.' && (!s[2] || s[2] == '/')))) + break; + while (*s++ != '/' && *s) + continue; + } + return !*s; + } return 0; }