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

Re: [bug] :P modifier and symlink loops



Stephane Chazelas wrote on Sun, 02 Feb 2020 17:03 +0000:
> 2020-02-02 08:10:21 +0000, Daniel Shahaf:
> [...]
> > However, in ${${:-"/tmp/loop/../foo"}} we can't meet the postcondition.
> > I think our options are either to throw an exception, like a glob with
> > no matches does, or to keep the additional components verbatim, as you
> > suggest.
> > 
> > Intuitively I lean towards the first option.  We aren't a CGI script,
> > where PATH_INFO is to be expected.  If we can't return a path without
> > dot and dot-dot components and without symlinks, we should raise an
> > error rather than continue silently. However, I'm open to alternatives.  
> 
> That works for me, I agree it's a pathological condition that
> may be worth reporting to the user, and to do that, there's
> probably no other alternative than to exit the current shell
> process.
> 
> > I think the first option could be implemented along the lines of:
> > 
> > 1. Call realpath($arg).
> > 2. If it returns ELOOP,  
> 
> ... and doesn't end in /..

I assume you mean "ends in slash-dot-dot".

> the . path components would have to be removed first as well.

Good point, but I'd expect slightly different behaviour.  Dot and
dot-dot components before the last, may-be-loop components don't need
special handling; they'll get resolved in the ordinary way.  However,
if [[ $arg == (*/|*/.|*/..) ]], the ELOOP special case shouldn't be
applied.

The cases that $arg is "", ".", or ".." are not going to report ELOOP,
are they?

> > call realpath(${arg:h}) and append "/${arg:t}".  
> 
> And what if *that* realpath() fails with ELOOP? Do we carry on
> with $arg:h:h?

No; we'll call zerr() [which sets errflag] and bail out, just like the
NO_MATCH option does.  Only the last path component (after the last slash,
or the entire string if it has no slashes) will be allowed to be a loop.

> > 3. Otherwise, throw an exception (i.e., set errflag).  
> [...]
> 

Cheers,

Daniel



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