Re: expand: Do not quote backslashes in unquoted parameter expansion

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Mar 27, 2018 at 05:54:53PM +0200, Harald van Dijk wrote:
>
> I was thinking about not making backslashes set metaflag in expmeta(): when
> the pathname component doesn't include *, ?, or [, but does include
> backslashes, then the if (metaflag == 0) block could handle that as long as
> it performs the lstat64() check unconditionally. There's no need to go
> through the opendir()/readdir()/closedir() path for that case. Since
> expmeta() is bypassed for words not containing any potentially-magic
> characters, the impact might be small enough.

Honestly such backslashes should be rare enough that I wouldn't
bother with such an optimisation.

> Regardless of whether metaflag is set, it would mean things like 'set "["'
> would start hitting the FS unnecessarily, if I understand correctly: the
> preglob()-expanded pattern is '\[', and expmeta() can no longer tell this
> apart from $v where v='\[' where a FS check would be required.

No it shouldn't.  We only mark [ is meta if there is a matching ].

> Perhaps preglob() should just be avoided, and expmeta() taught to respect
> both '\\' and CTLESC. '\\' would be a metacharacter and require a FS hit,
> CTLESC wouldn't require it. This would also avoid some memory allocations.

We need preglob for glob(3).  I want to minimise the amount of code
difference between the glob path and the expmeta path.

>     if (!strpbrk(str->text, metachars))
>         goto nometa;
> 
> in expandmeta() is done before preglob() is called. Here, it is still not
> necessary to include CTLESC.

We could move it after preglob.

> This doesn't matter much yet, but yeah, it will if you decide to enable
> --enable-glob by default in the future. As long as you don't include
> GLOB_NOESCAPE, then normally, it should be taken as escaping the next
> character, but it might still trigger GLOB_NOMAGIC to return early. If it
> does, I'd take that as a glibc bug, but that doesn't help dash.

Well at least glibc glob(3) actually works now after 20 years of
trying :)

Cheers,
-- 
Email: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux