On 27/03/2018 19:02, Herbert Xu wrote:
On Tue, Mar 27, 2018 at 06:48:45PM +0200, Harald van Dijk wrote:

Backslashes coming from parameters, sure, but backslashes introduced by
preglob(), I'm not so sure.

Right.  I guess we could change it so that CTLESC is preserved
to distinguish between the backslashes from parameter expansion
vs. backslashes from open input.

Thinking about it some more, see below.

The [ character would mark the whole string possibly-meta in expandmeta(),
and the CTLESC wouldn't be seen there. Then, preglob() turns it into \[, and
expmeta() wouldn't take [ as a meta character, but would take \ as a meta

Oh I though you were talking about test/[, I didn't see the set.
But why would someone do set "["?

It was just the most basic command I could think of that shouldn't hit the FS, currently doesn't hit the FS, and would start hitting the FS if backslash gets taken as a metacharacter. Anything containing a quoted metacharacter would do. I suppose I could have used echo "[ ok ]" instead for something that's more likely to pop up in a real script.

Then, how about moving some of expmeta()'s checks to return early outside of
it, so that they can also be done in the glob() case?

We could.

expandmeta() is implemented twice, once for the glob() case, once for the expmeta() case. There is not much code shared between them except for preglob(). preglob(), through _rmescapes(), already has to go over the whole string and check each character. If that can be made to return an indication somehow of whether it has seen metacharacters, that could be used for both cases. Perhaps an additional flag that, when set, lets it return NULL (and freeing the allocated string) if no metacharacters were seen? That means expmeta() doesn't need to learn about CTLESC, means there's no need to go over the string a second time in the glob() case to really turn CTLESC into \, and means GLOB_NOMAGIC becomes unnecessary and can be removed as a workaround for glibc bugs.

Harald van Dijk
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to