[libvirt] [PATCH] xml: shell-escape domain name in comment
Eric Blake
eblake at redhat.com
Wed Oct 24 14:39:28 UTC 2012
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 at redhat.com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 617 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20121024/177f6420/attachment-0001.sig>
More information about the libvir-list
mailing list