]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Fix Xen SEXPR generation to properly quote strings containing ()
authorDaniel P. Berrange <berrange@redhat.com>
Mon, 23 Aug 2010 13:00:22 +0000 (14:00 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Wed, 13 Oct 2010 15:42:48 +0000 (16:42 +0100)
* 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
tests/sexpr2xmldata/sexpr2xml-boot-grub.sexpr [new file with mode: 0644]
tests/sexpr2xmldata/sexpr2xml-boot-grub.xml [new file with mode: 0644]
tests/sexpr2xmltest.c
tests/xml2sexprdata/xml2sexpr-boot-grub.sexpr [new file with mode: 0644]
tests/xml2sexprdata/xml2sexpr-boot-grub.xml [new file with mode: 0644]
tests/xml2sexprtest.c

index 21840608533faf2bf116a2a119b0a1c4efe10887..330280e1cacbeceff0cb21c5a878108dc71bfcf1 100644 (file)
@@ -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 (file)
index 0000000..f42fc32
--- /dev/null
@@ -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 (file)
index 0000000..9221bdd
--- /dev/null
@@ -0,0 +1,26 @@
+<domain type='xen' id='6'>
+  <name>pvtest</name>
+  <uuid>596a5d21-71f4-8fb2-e068-e2386a5c413e</uuid>
+  <memory>430080</memory>
+  <currentMemory>430080</currentMemory>
+  <vcpu>2</vcpu>
+  <os>
+    <type>linux</type>
+    <kernel>/usr/lib/xen/boot/pv-grub-x86_64.gz</kernel>
+    <cmdline>(hd0,0)/grub/menu.lst</cmdline>
+  </os>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>destroy</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <disk type='block' device='disk'>
+      <driver name='phy'/>
+      <source dev='/dev/MainVG/GuestVG'/>
+      <target dev='xvda' bus='xen'/>
+    </disk>
+    <console type='pty'>
+      <target type='xen' port='0'/>
+    </console>
+  </devices>
+</domain>
index 8c75c52cabfcb1d49ea4887b3580a0127bbb5319..d62b44f8d69bff40bb21395f2df90bd587643123 100644 (file)
@@ -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 (file)
index 0000000..a9d14df
--- /dev/null
@@ -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 (file)
index 0000000..b9b1c9f
--- /dev/null
@@ -0,0 +1,21 @@
+<domain type='xen' id='15'>
+  <name>pvtest</name>
+  <uuid>596a5d2171f48fb2e068e2386a5c413e</uuid>
+  <os>
+    <type>linux</type>
+    <kernel>/usr/lib/xen/boot/pv-grub-x86_64.gz</kernel>
+    <cmdline>(hd0,0)/grub/menu.lst</cmdline>
+  </os>
+  <memory>430080</memory>
+  <vcpu>2</vcpu>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>destroy</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <disk type='block' device='disk'>
+      <source dev='/dev/MainVG/GuestLV'/>
+      <target dev='xvda'/>
+    </disk>
+    <console tty='/dev/pts/4'/>
+  </devices>
+</domain>
index 49b757467de3e84548ba7a4bcc70d5c432511b21..77cf760597e765603277c083dd4453daacc5e5dc 100644 (file)
@@ -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);