[libvirt] [PATCH v3] xml: print uuids in the warning

Peter Krempa pkrempa at redhat.com
Mon Oct 29 13:35:47 UTC 2012


On 10/29/12 13:15, Ján Tomko wrote:
> In the XML warning, we print a virsh command line that can be used to
> edit that XML. This patch prints UUIDs if the entity name contains
> special characters (like shell metacharacters, or "--" that would break
> parsing of the XML comment). If the entity doesn't have a UUID, just
> print the virsh command that can be used to edit it.
>
> ---
> As opposed to previous versions, this doesn't use virBuffer and it
> doesn't do any shell escaping at all. The name parameter can be null
> now.
>
> commit 9b704ab8235af010b1fda4886201aab02098b969
>      xml: omit domain name from comment if it contains double hyphen
> only checked the 'name' parameter of virXMLEmitWarning. virXMLSaveFile
> invocation when creating a snapshot put the domain name in 'cmd', which
> means that snapshot XMLs of a domain with "--" in the name still can't be
> parsed by libvirt.
> ---
>   src/conf/domain_conf.c            |    6 +++++-
>   src/conf/network_conf.c           |    6 +++++-
>   src/conf/nwfilter_conf.c          |   12 ++++++++++--
>   src/conf/storage_conf.c           |    6 +++++-
>   src/libvirt_private.syms          |    1 +
>   src/parallels/parallels_storage.c |    3 +--
>   src/qemu/qemu_domain.c            |    9 +--------
>   src/util/xml.c                    |   18 +++++++++++++-----
>   src/util/xml.h                    |    1 +
>   9 files changed, 42 insertions(+), 20 deletions(-)
>

[...]

> diff --git a/src/util/xml.c b/src/util/xml.c
> index f3dc256..dad9227 100644
> --- a/src/util/xml.c
> +++ b/src/util/xml.c
> @@ -780,6 +780,16 @@ error:
>       goto cleanup;
>   }
>
> +const char *virXMLPickShellSafeComment(const char *str1, const char *str2)
> +{
> +    if(str1 && !strpbrk(str1, "\r\t\n !\"#$&'()*;<>?[\\]^`{|}~") &&
> +       !strstr(str1, "--"))
> +        return str1;
> +    if(str2 && !strpbrk(str2, "\r\t\n !\"#$&'()*;<>?[\\]^`{|}~") &&
> +       !strstr(str2, "--"))
> +        return str2;

For now, this second check is not really needed as you always pass the 
UUID that is safe, but it doesn't hurt to check anyways if somebody 
would like to use this helper somewhere else.

> +    return NULL;
> +}
>
>   static int virXMLEmitWarning(int fd,
>                                const char *name,
> @@ -794,7 +804,7 @@ OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:\n\
>   or other application using the libvirt API.\n\
>   -->\n\n";

Hm, I don't like formatting of these strings. I'll send a follow-up to 
clean this up as it's not caused by you.

>
> -    if (fd < 0 || !name || !cmd) {
> +    if (fd < 0 || !cmd) {
>           errno = EINVAL;
>           return -1;
>       }

ACK && pushed.

Peter




More information about the libvir-list mailing list