[Libguestfs] [PATCH] Replace shell_quote function with %Q and %R printf specifiers.

Matthew Booth mbooth at redhat.com
Tue Jul 28 09:13:04 UTC 2009


On 28/07/09 09:34, Richard W.M. Jones wrote:
> On Mon, Jul 27, 2009 at 11:19:00PM +0100, Matthew Booth wrote:
>> #define SYSROOT "/sysroot"
>>
>> snprintf (cmd, sizeof cmd, "cat " SYSROOT "%s", path);
>
> This doesn't work because the path must be shell-quoted.
>
> (Also SYSROOT is no longer a fixed string - but now a variable).
>
> Rich.
>

How about:

snprintf (cmd, sizeof cmd, "cat " SYSROOT "%Q", path);

or:

snprintf (cmd, sizeof cmd, "cat %s%Q", sysroot, path);

All you have to do is ensure that SYSROOT, or sysroot if it's a 
variable, is appropriately escaped in advance. This shouldn't be 
difficult as it's specified in the program itself.

Matt
-- 
Matthew Booth, RHCA, RHCSS
Red Hat Engineering, Virtualisation Team

M:       +44 (0)7977 267231
GPG ID:  D33C3490
GPG FPR: 3733 612D 2D05 5458 8A8A 1600 3441 EA19 D33C 3490




More information about the Libguestfs mailing list