Re: [PATCH] xml: shell-escape domain name in comment

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

 



On 10/24/2012 06:03 AM, Ján Tomko wrote:
> Add virBufferEscapeShellXMLComment function that both quotes a string so
> shell deosn't interpert any special characters in it and makes sure that
> there's no "--" in it, to avoid clashes with XML comments.
> 
> virXMLEmitWarning is changed to use virBuffer and use the above function
> on the domain name.
> ---
>  src/libvirt_private.syms |    1 +
>  src/util/buf.c           |   66 ++++++++++++++++++++++++++++++++++++++++++++++
>  src/util/buf.h           |    1 +
>  src/util/xml.c           |   52 +++++++++++++++---------------------
>  4 files changed, 90 insertions(+), 30 deletions(-)
> 
> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
> index 699c9a3..a49d5dc 100644
> --- a/src/libvirt_private.syms
> +++ b/src/libvirt_private.syms
> @@ -37,6 +37,7 @@ virBufferError;
>  virBufferEscape;
>  virBufferEscapeSexpr;
>  virBufferEscapeShell;
> +virBufferEscapeShellXML;

This name doesn't match.

> +    *out++ = '\'';
> +    while (*cur != 0) {
> +        if (*cur == '\'') {
> +            *out++ = '\'';
> +            /* Replace literal ' with a close ', a \', and a open ' */
> +            *out++ = '\\';
> +            *out++ = '\'';
> +        } else if (*cur == '-' &&  prev == '-') {

Is two spaces after && intentional?


> +    virBufferAddLit(&buf, "<!--\n"
> +"WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE\n"
> +"OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:\n"
> +"  virsh ");
> +    virBufferAdd(&buf, cmd, -1);
> +    virBufferAddLit(&buf," ");

virBufferAddChar() is more efficient for a single byte.

The idea of using UUID instead of name for problematic names sounds
appealing to me.

-- 
Eric Blake   eblake@xxxxxxxxxx    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]