[systemd-devel] [PATCH 7/9] nspawn: escape paths in overlay mount options

Lennart Poettering lennart at poettering.net
Fri Jun 19 03:42:10 PDT 2015


On Fri, 19.06.15 11:17, Richard Maw (richard.maw at codethink.co.uk) wrote:

> > Also, it's really inefficient, since strreplace() goes through the
> > string each time from the beginning.
> 
> I was looking to do something simple rather than fast, as this isn't a
> particularly latency sensitive bit of code, and I wasn't confident in
> the need of a generic solution, but if you think it'll have wider use,
> that's fine by me.

Yeah, the need for a shell-like rather than C-like escaping function
comes up every now and then, and we should really fix this properly
for once...

> > I think it would make sense to add a generic 
> > 
> >   char *shell_escape(const char *s, const char *bad);
> > 
> > that works like xescape() but applies shell-style escaping instead of
> > C-style escaping.
> 
> This isn't exactly shell escaping as I understand it, as that would also
> require putting quotation marks aroud the string in certain circumstances,
> and shell_maybe_quote() handles that already.

Well, it *is* shell escaping, but a different kind. After all for the
shell 

       "foo bar" 

and 

       foo\ bar

are equivalent. Most folks would argue though that the first is
prettier to look at, and that's what shell_maybe_quote() does. But the
second is valid shell escaping too, and in the overlayfs case what we
actually need. Hence I think we need both calls...

> I'd call it backslash_escape() and possibly use it inside
> shell_maybe_quote().

Well, C-style escaping also uses backslashes... I think we should
still call it shell_escape() and shell_maybe_quote()...

Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list