From 3a092f38994a57f3c12397464f7532cb82e15e14 Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Mon, 23 Aug 2010 14:00:22 +0100 Subject: [PATCH] Fix Xen SEXPR generation to properly quote strings containing () * src/xen/sexpr.c: Ensure () are escaped in sexpr2string * tests/sexpr2xmldata/sexpr2xml-boot-grub.sexpr, tests/sexpr2xmldata/sexpr2xml-boot-grub.xml, tests/xml2sexprdata/xml2sexpr-boot-grub.sexpr, tests/xml2sexprdata/xml2sexpr-boot-grub.xml: Data files to check escaping * tests/sexpr2xmltest.c, tests/xml2sexprtest.c: Add boot-grub escaping test case --- src/xen/sexpr.c | 4 ++- tests/sexpr2xmldata/sexpr2xml-boot-grub.sexpr | 1 + tests/sexpr2xmldata/sexpr2xml-boot-grub.xml | 26 +++++++++++++++++++ tests/sexpr2xmltest.c | 2 ++ tests/xml2sexprdata/xml2sexpr-boot-grub.sexpr | 1 + tests/xml2sexprdata/xml2sexpr-boot-grub.xml | 21 +++++++++++++++ tests/xml2sexprtest.c | 2 ++ 7 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 tests/sexpr2xmldata/sexpr2xml-boot-grub.sexpr create mode 100644 tests/sexpr2xmldata/sexpr2xml-boot-grub.xml create mode 100644 tests/xml2sexprdata/xml2sexpr-boot-grub.sexpr create mode 100644 tests/xml2sexprdata/xml2sexpr-boot-grub.xml diff --git a/src/xen/sexpr.c b/src/xen/sexpr.c index 2184060853..330280e1ca 100644 --- a/src/xen/sexpr.c +++ b/src/xen/sexpr.c @@ -244,7 +244,9 @@ sexpr2string(const struct sexpr * sexpr, char *buffer, size_t n_buffer) ret += tmp; break; case SEXPR_VALUE: - if (strchr(sexpr->u.value, ' ')) + if (strchr(sexpr->u.value, ' ') || + strchr(sexpr->u.value, ')') || + strchr(sexpr->u.value, '(')) tmp = snprintf(buffer + ret, n_buffer - ret, "'%s'", sexpr->u.value); else diff --git a/tests/sexpr2xmldata/sexpr2xml-boot-grub.sexpr b/tests/sexpr2xmldata/sexpr2xml-boot-grub.sexpr new file mode 100644 index 0000000000..f42fc32901 --- /dev/null +++ b/tests/sexpr2xmldata/sexpr2xml-boot-grub.sexpr @@ -0,0 +1 @@ +(domain (domid 6)(name 'pvtest')(memory 420)(maxmem 420)(vcpus 2)(uuid '596a5d2171f48fb2e068e2386a5c413e')(on_poweroff 'destroy')(on_reboot 'destroy')(on_crash 'destroy')(image (linux (kernel '/usr/lib/xen/boot/pv-grub-x86_64.gz')(args '(hd0,0)/grub/menu.lst')))(device (vbd (dev 'xvda')(uname 'phy:/dev/MainVG/GuestVG')(mode 'w')))) diff --git a/tests/sexpr2xmldata/sexpr2xml-boot-grub.xml b/tests/sexpr2xmldata/sexpr2xml-boot-grub.xml new file mode 100644 index 0000000000..9221bdd7ff --- /dev/null +++ b/tests/sexpr2xmldata/sexpr2xml-boot-grub.xml @@ -0,0 +1,26 @@ + + pvtest + 596a5d21-71f4-8fb2-e068-e2386a5c413e + 430080 + 430080 + 2 + + linux + /usr/lib/xen/boot/pv-grub-x86_64.gz + (hd0,0)/grub/menu.lst + + + destroy + destroy + destroy + + + + + + + + + + + diff --git a/tests/sexpr2xmltest.c b/tests/sexpr2xmltest.c index 8c75c52cab..d62b44f8d6 100644 --- a/tests/sexpr2xmltest.c +++ b/tests/sexpr2xmltest.c @@ -172,6 +172,8 @@ mymain(int argc, char **argv) DO_TEST("fv-net-ioemu", "fv-net-ioemu", 1); DO_TEST("fv-net-netfront", "fv-net-netfront", 1); + DO_TEST("boot-grub", "boot-grub", 1); + virCapabilitiesFree(caps); return(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE); diff --git a/tests/xml2sexprdata/xml2sexpr-boot-grub.sexpr b/tests/xml2sexprdata/xml2sexpr-boot-grub.sexpr new file mode 100644 index 0000000000..a9d14df68d --- /dev/null +++ b/tests/xml2sexprdata/xml2sexpr-boot-grub.sexpr @@ -0,0 +1 @@ +(vm (name 'pvtest')(memory 420)(maxmem 420)(vcpus 2)(uuid '596a5d21-71f4-8fb2-e068-e2386a5c413e')(on_poweroff 'destroy')(on_reboot 'destroy')(on_crash 'destroy')(image (linux (kernel '/usr/lib/xen/boot/pv-grub-x86_64.gz')(args (hd0,0)/grub/menu.lst)))(device (vbd (dev 'xvda')(uname 'phy:/dev/MainVG/GuestLV')(mode 'w')))) \ No newline at end of file diff --git a/tests/xml2sexprdata/xml2sexpr-boot-grub.xml b/tests/xml2sexprdata/xml2sexpr-boot-grub.xml new file mode 100644 index 0000000000..b9b1c9f784 --- /dev/null +++ b/tests/xml2sexprdata/xml2sexpr-boot-grub.xml @@ -0,0 +1,21 @@ + + pvtest + 596a5d2171f48fb2e068e2386a5c413e + + linux + /usr/lib/xen/boot/pv-grub-x86_64.gz + (hd0,0)/grub/menu.lst + + 430080 + 2 + destroy + destroy + destroy + + + + + + + + diff --git a/tests/xml2sexprtest.c b/tests/xml2sexprtest.c index 49b757467d..77cf760597 100644 --- a/tests/xml2sexprtest.c +++ b/tests/xml2sexprtest.c @@ -161,6 +161,8 @@ mymain(int argc, char **argv) DO_TEST("fv-net-ioemu", "fv-net-ioemu", "fvtest", 1); DO_TEST("fv-net-netfront", "fv-net-netfront", "fvtest", 1); + DO_TEST("boot-grub", "boot-grub", "fvtest", 1); + virCapabilitiesFree(caps); return(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE); -- GitLab