[libvirt] [PATCH] Don't copy sexpr node value that is an empty string

Xen4.1 initializes some unspecified sexpr config items to an empty string, unlike previous Xen versions that would leave the item unset. E.g. the kernel item for an HVM guest (non-direct kernel boot): Xen4.0 and earlier ... (image (hvm (kernel ) ... Xen4.1 ... (image (hvm (kernel '') ... The empty string for kernel causes some grief in subsequent parsing where existence of specified kernel is checked, e.g. if (!def->os.kernel) ... This patch solves the problem in sexpr_node_copy() by not copying a node containing an empty string. --- src/util/sexpr.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/src/util/sexpr.c b/src/util/sexpr.c index 0e30087..3523d76 100644 --- a/src/util/sexpr.c +++ b/src/util/sexpr.c @@ -519,7 +519,7 @@ int sexpr_node_copy(const struct sexpr *sexpr, const char *node, char **dst) { const char *val = sexpr_node(sexpr, node); - if (val) { + if (val && *val) { *dst = strdup(val); if (!(*dst)) return -1; -- 1.7.7

On 11/18/2011 03:16 PM, Jim Fehlig wrote:
Xen4.1 initializes some unspecified sexpr config items to an empty string, unlike previous Xen versions that would leave the item unset. E.g. the kernel item for an HVM guest (non-direct kernel boot):
Xen4.0 and earlier ... (image (hvm (kernel ) ...
Xen4.1 ... (image (hvm (kernel '') ...
Thanks for the examples; that helps understand the patch.
- if (val) { + if (val && *val) { *dst = strdup(val);
ACK. -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

Eric Blake wrote:
On 11/18/2011 03:16 PM, Jim Fehlig wrote:
Xen4.1 initializes some unspecified sexpr config items to an empty string, unlike previous Xen versions that would leave the item unset. E.g. the kernel item for an HVM guest (non-direct kernel boot):
Xen4.0 and earlier ... (image (hvm (kernel ) ...
Xen4.1 ... (image (hvm (kernel '') ...
Thanks for the examples; that helps understand the patch.
- if (val) { + if (val && *val) { *dst = strdup(val);
ACK.
Thanks Eric, pushed. Jim
participants (2)
-
Eric Blake
-
Jim Fehlig