render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
a41c76
From ba88fc4f04428c1064bc4eee85acbdf1a3123c4c Mon Sep 17 00:00:00 2001
a41c76
Message-Id: <ba88fc4f04428c1064bc4eee85acbdf1a3123c4c@dist-git>
a41c76
From: Peter Krempa <pkrempa@redhat.com>
a41c76
Date: Mon, 30 Mar 2020 17:21:40 +0200
a41c76
Subject: [PATCH] virStorageSourceNetCookieValidate: Accept quoted cookie value
a41c76
MIME-Version: 1.0
a41c76
Content-Type: text/plain; charset=UTF-8
a41c76
Content-Transfer-Encoding: 8bit
a41c76
a41c76
The quotes are forbidden only inside the value, but the value itself may
a41c76
be enclosed in quotes. Fix the RNG schema and validator and add a test
a41c76
case.
a41c76
a41c76
https://bugzilla.redhat.com/show_bug.cgi?id=1804750
a41c76
a41c76
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
a41c76
Reviewed-by: Ján Tomko <jtomko@redhat.com>
a41c76
(cherry picked from commit b9166baebe70a4b3577ddb6b2ee6af0dd4f60759)
a41c76
Message-Id: <f8f910f4e61e0e9434591a02c5d2e50b3d78edc5.1585581552.git.pkrempa@redhat.com>
a41c76
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
a41c76
---
a41c76
 docs/schemas/domaincommon.rng                 |  2 +-
a41c76
 src/util/virstoragefile.c                     | 19 ++++++++++++++++++-
a41c76
 .../disk-network-http.x86_64-latest.args      |  4 ++--
a41c76
 tests/qemuxml2argvdata/disk-network-http.xml  |  4 ++--
a41c76
 .../disk-network-http.x86_64-latest.xml       |  4 ++--
a41c76
 5 files changed, 25 insertions(+), 8 deletions(-)
a41c76
a41c76
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
a41c76
index 3a0edbed97..ac6f180382 100644
a41c76
--- a/docs/schemas/domaincommon.rng
a41c76
+++ b/docs/schemas/domaincommon.rng
a41c76
@@ -1846,7 +1846,7 @@
a41c76
             </data>
a41c76
           </attribute>
a41c76
           <data type="string">
a41c76
-            <param name="pattern">[!#$%&'()*+\-./0-9:>=<?@A-Z\^_`\[\]a-z|~]+</param>
a41c76
+            <param name="pattern">"?[!#$%&'()*+\-./0-9:>=<?@A-Z\^_`\[\]a-z|~]+"?</param>
a41c76
           </data>
a41c76
         </element>
a41c76
       </oneOrMore>
a41c76
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
a41c76
index 3eb32edc2a..f8d741f040 100644
a41c76
--- a/src/util/virstoragefile.c
a41c76
+++ b/src/util/virstoragefile.c
a41c76
@@ -2217,6 +2217,10 @@ static const char virStorageSourceCookieNameInvalidChars[] =
a41c76
 static int
a41c76
 virStorageSourceNetCookieValidate(virStorageNetCookieDefPtr def)
a41c76
 {
a41c76
+    g_autofree char *val = g_strdup(def->value);
a41c76
+    const char *checkval = val;
a41c76
+    size_t len = strlen(val);
a41c76
+
a41c76
     /* name must have at least 1 character */
a41c76
     if (*(def->name) == '\0') {
a41c76
         virReportError(VIR_ERR_XML_ERROR, "%s",
a41c76
@@ -2233,8 +2237,21 @@ virStorageSourceNetCookieValidate(virStorageNetCookieDefPtr def)
a41c76
         return -1;
a41c76
     }
a41c76
 
a41c76
+    /* check for optional quotes around the cookie value string */
a41c76
+    if (val[0] == '"') {
a41c76
+        if (val[len - 1] != '"') {
a41c76
+            virReportError(VIR_ERR_XML_ERROR,
a41c76
+                           _("value of cookie '%s' contains invalid characters"),
a41c76
+                           def->name);
a41c76
+            return -1;
a41c76
+        }
a41c76
+
a41c76
+        val[len - 1] = '\0';
a41c76
+        checkval++;
a41c76
+    }
a41c76
+
a41c76
     /* check invalid characters in value */
a41c76
-    if (virStringHasChars(def->value, virStorageSourceCookieValueInvalidChars)) {
a41c76
+    if (virStringHasChars(checkval, virStorageSourceCookieValueInvalidChars)) {
a41c76
         virReportError(VIR_ERR_XML_ERROR,
a41c76
                        _("value of cookie '%s' contains invalid characters"),
a41c76
                        def->name);
a41c76
diff --git a/tests/qemuxml2argvdata/disk-network-http.x86_64-latest.args b/tests/qemuxml2argvdata/disk-network-http.x86_64-latest.args
a41c76
index 2f2849ebdf..46aa5f23ce 100644
a41c76
--- a/tests/qemuxml2argvdata/disk-network-http.x86_64-latest.args
a41c76
+++ b/tests/qemuxml2argvdata/disk-network-http.x86_64-latest.args
a41c76
@@ -42,7 +42,7 @@ id=virtio-disk0,bootindex=1 \
a41c76
 -device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x3,drive=libvirt-3-format,\
a41c76
 id=virtio-disk1 \
a41c76
 -object secret,id=libvirt-2-storage-httpcookie-secret0,\
a41c76
-data=DrPR9NA6GKJb7qi1KbjHad3f3UIGTTDmAmOZHHv1F5w5T8rhnk3f+uSKStHe0J2O,\
a41c76
+data=DrPR9NA6GKJb7qi1KbjHaealKEMVtOWUl2h3yvO5lgIh6cyLHemmlg+h9fcgwREA,\
a41c76
 keyid=masterKey0,iv=AAECAwQFBgcICQoLDA0ODw==,format=base64 \
a41c76
 -blockdev '{"driver":"http","url":"http://example.org:1234/test3.img",\
a41c76
 "cookie-secret":"libvirt-2-storage-httpcookie-secret0",\
a41c76
@@ -52,7 +52,7 @@ keyid=masterKey0,iv=AAECAwQFBgcICQoLDA0ODw==,format=base64 \
a41c76
 -device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x4,drive=libvirt-2-format,\
a41c76
 id=virtio-disk2 \
a41c76
 -object secret,id=libvirt-1-storage-httpcookie-secret0,\
a41c76
-data=DrPR9NA6GKJb7qi1KbjHad3f3UIGTTDmAmOZHHv1F5w5T8rhnk3f+uSKStHe0J2O,\
a41c76
+data=DrPR9NA6GKJb7qi1KbjHaealKEMVtOWUl2h3yvO5lgIh6cyLHemmlg+h9fcgwREA,\
a41c76
 keyid=masterKey0,iv=AAECAwQFBgcICQoLDA0ODw==,format=base64 \
a41c76
 -blockdev '{"driver":"https","url":"https://example.org:1234/test4.img",\
a41c76
 "sslverify":false,"cookie-secret":"libvirt-1-storage-httpcookie-secret0",\
a41c76
diff --git a/tests/qemuxml2argvdata/disk-network-http.xml b/tests/qemuxml2argvdata/disk-network-http.xml
a41c76
index 20024c732e..93e6617433 100644
a41c76
--- a/tests/qemuxml2argvdata/disk-network-http.xml
a41c76
+++ b/tests/qemuxml2argvdata/disk-network-http.xml
a41c76
@@ -35,7 +35,7 @@
a41c76
         <host name='example.org' port='1234'/>
a41c76
         <cookies>
a41c76
           <cookie name='test'>testcookievalue</cookie>
a41c76
-          <cookie name='test2'>blurb</cookie>
a41c76
+          <cookie name='test2'>"blurb"</cookie>
a41c76
         </cookies>
a41c76
       </source>
a41c76
       <target dev='vdc' bus='virtio'/>
a41c76
@@ -47,7 +47,7 @@
a41c76
         <ssl verify='no'/>
a41c76
         <cookies>
a41c76
           <cookie name='test'>testcookievalue</cookie>
a41c76
-          <cookie name='test2'>blurb</cookie>
a41c76
+          <cookie name='test2'>"blurb"</cookie>
a41c76
         </cookies>
a41c76
       </source>
a41c76
       <target dev='vdd' bus='virtio'/>
a41c76
diff --git a/tests/qemuxml2xmloutdata/disk-network-http.x86_64-latest.xml b/tests/qemuxml2xmloutdata/disk-network-http.x86_64-latest.xml
a41c76
index 238a5fef58..60073c227c 100644
a41c76
--- a/tests/qemuxml2xmloutdata/disk-network-http.x86_64-latest.xml
a41c76
+++ b/tests/qemuxml2xmloutdata/disk-network-http.x86_64-latest.xml
a41c76
@@ -38,7 +38,7 @@
a41c76
         <host name='example.org' port='1234'/>
a41c76
         <cookies>
a41c76
           <cookie name='test'>testcookievalue</cookie>
a41c76
-          <cookie name='test2'>blurb</cookie>
a41c76
+          <cookie name='test2'>"blurb"</cookie>
a41c76
         </cookies>
a41c76
       </source>
a41c76
       <target dev='vdc' bus='virtio'/>
a41c76
@@ -51,7 +51,7 @@
a41c76
         <ssl verify='no'/>
a41c76
         <cookies>
a41c76
           <cookie name='test'>testcookievalue</cookie>
a41c76
-          <cookie name='test2'>blurb</cookie>
a41c76
+          <cookie name='test2'>"blurb"</cookie>
a41c76
         </cookies>
a41c76
       </source>
a41c76
       <target dev='vdd' bus='virtio'/>
a41c76
-- 
a41c76
2.26.0
a41c76