[PATCH 0/2] Accept http cookies with quoted value

The validator didn't accept the quoted version of the cookie value. Add a test and fix the issue. Peter Krempa (2): qemuxml2xmltest: Wire up 'disk-network-http' case virStorageSourceNetCookieValidate: Accept quoted cookie value docs/schemas/domaincommon.rng | 2 +- src/util/virstoragefile.c | 19 ++++- .../disk-network-http.x86_64-latest.args | 4 +- tests/qemuxml2argvdata/disk-network-http.xml | 4 +- .../disk-network-http.x86_64-latest.xml | 71 +++++++++++++++++++ tests/qemuxml2xmltest.c | 2 + 6 files changed, 96 insertions(+), 6 deletions(-) create mode 100644 tests/qemuxml2xmloutdata/disk-network-http.x86_64-latest.xml -- 2.24.1

Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- .../disk-network-http.x86_64-latest.xml | 71 +++++++++++++++++++ tests/qemuxml2xmltest.c | 2 + 2 files changed, 73 insertions(+) create mode 100644 tests/qemuxml2xmloutdata/disk-network-http.x86_64-latest.xml diff --git a/tests/qemuxml2xmloutdata/disk-network-http.x86_64-latest.xml b/tests/qemuxml2xmloutdata/disk-network-http.x86_64-latest.xml new file mode 100644 index 0000000000..9e78785d0d --- /dev/null +++ b/tests/qemuxml2xmloutdata/disk-network-http.x86_64-latest.xml @@ -0,0 +1,71 @@ +<domain type='kvm'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type arch='x86_64' machine='pc'>hvm</type> + <boot dev='hd'/> + </os> + <cpu mode='custom' match='exact' check='none'> + <model fallback='forbid'>qemu64</model> + </cpu> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu-system-x86_64</emulator> + <disk type='network' device='disk'> + <driver name='qemu' type='raw'/> + <source protocol='http' name='test.img'> + <host name='example.org' port='80'/> + <timeout seconds='1234'/> + </source> + <target dev='vda' bus='virtio'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> + </disk> + <disk type='network' device='disk'> + <driver name='qemu' type='raw'/> + <source protocol='https' name='test2.img'> + <host name='example.org' port='443'/> + <readahead size='1024'/> + </source> + <target dev='vdb' bus='virtio'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> + </disk> + <disk type='network' device='disk'> + <driver name='qemu' type='raw'/> + <source protocol='http' name='test3.img'> + <host name='example.org' port='1234'/> + <cookies> + <cookie name='test'>testcookievalue</cookie> + <cookie name='test2'>blurb</cookie> + </cookies> + </source> + <target dev='vdc' bus='virtio'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/> + </disk> + <disk type='network' device='disk'> + <driver name='qemu' type='raw'/> + <source protocol='https' name='test4.img'> + <host name='example.org' port='1234'/> + <ssl verify='no'/> + <cookies> + <cookie name='test'>testcookievalue</cookie> + <cookie name='test2'>blurb</cookie> + </cookies> + </source> + <target dev='vdd' bus='virtio'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/> + </disk> + <controller type='usb' index='0' model='piix3-uhci'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> + </controller> + <controller type='pci' index='0' model='pci-root'/> + <input type='mouse' bus='ps2'/> + <input type='keyboard' bus='ps2'/> + <memballoon model='none'/> + </devices> +</domain> diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index a3c25b4a76..a0d27fdcf8 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -1095,6 +1095,8 @@ mymain(void) DO_TEST("disk-backing-chains-index", NONE); DO_TEST("disk-backing-chains-noindex", NONE); + DO_TEST_CAPS_LATEST("disk-network-http"); + DO_TEST("chardev-label", QEMU_CAPS_DEVICE_VIRTIO_RNG); -- 2.24.1

The quotes are forbidden only inside the value, but the value itself may be enclosed in quotes. Fix the RNG schema and validator and add a test case. https://bugzilla.redhat.com/show_bug.cgi?id=1804750 Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- docs/schemas/domaincommon.rng | 2 +- src/util/virstoragefile.c | 19 ++++++++++++++++++- .../disk-network-http.x86_64-latest.args | 4 ++-- tests/qemuxml2argvdata/disk-network-http.xml | 4 ++-- .../disk-network-http.x86_64-latest.xml | 4 ++-- 5 files changed, 25 insertions(+), 8 deletions(-) diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index d79dee650e..02f1ab1982 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -1846,7 +1846,7 @@ </data> </attribute> <data type="string"> - <param name="pattern">[!#$%&'()*+\-./0-9:>=<?@A-Z\^_`\[\]a-z|~]+</param> + <param name="pattern">"?[!#$%&'()*+\-./0-9:>=<?@A-Z\^_`\[\]a-z|~]+"?</param> </data> </element> </oneOrMore> diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index d81ed70a97..c43e52d1f6 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -2217,6 +2217,10 @@ static const char virStorageSourceCookieNameInvalidChars[] = static int virStorageSourceNetCookieValidate(virStorageNetCookieDefPtr def) { + g_autofree char *val = g_strdup(def->value); + const char *checkval = val; + size_t len = strlen(val); + /* name must have at least 1 character */ if (*(def->name) == '\0') { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -2233,8 +2237,21 @@ virStorageSourceNetCookieValidate(virStorageNetCookieDefPtr def) return -1; } + /* check for optional quotes around the cookie value string */ + if (val[0] == '"') { + if (val[len - 1] != '"') { + virReportError(VIR_ERR_XML_ERROR, + _("value of cookie '%s' contains invalid characters"), + def->name); + return -1; + } + + val[len - 1] = '\0'; + checkval++; + } + /* check invalid characters in value */ - if (virStringHasChars(def->value, virStorageSourceCookieValueInvalidChars)) { + if (virStringHasChars(checkval, virStorageSourceCookieValueInvalidChars)) { virReportError(VIR_ERR_XML_ERROR, _("value of cookie '%s' contains invalid characters"), def->name); diff --git a/tests/qemuxml2argvdata/disk-network-http.x86_64-latest.args b/tests/qemuxml2argvdata/disk-network-http.x86_64-latest.args index e14498f778..ed44424dc3 100644 --- a/tests/qemuxml2argvdata/disk-network-http.x86_64-latest.args +++ b/tests/qemuxml2argvdata/disk-network-http.x86_64-latest.args @@ -43,7 +43,7 @@ id=virtio-disk0,bootindex=1 \ -device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x3,drive=libvirt-3-format,\ id=virtio-disk1 \ -object secret,id=libvirt-2-storage-httpcookie-secret0,\ -data=DrPR9NA6GKJb7qi1KbjHad3f3UIGTTDmAmOZHHv1F5w5T8rhnk3f+uSKStHe0J2O,\ +data=DrPR9NA6GKJb7qi1KbjHaealKEMVtOWUl2h3yvO5lgIh6cyLHemmlg+h9fcgwREA,\ keyid=masterKey0,iv=AAECAwQFBgcICQoLDA0ODw==,format=base64 \ -blockdev '{"driver":"http","url":"http://example.org:1234/test3.img",\ "cookie-secret":"libvirt-2-storage-httpcookie-secret0",\ @@ -53,7 +53,7 @@ keyid=masterKey0,iv=AAECAwQFBgcICQoLDA0ODw==,format=base64 \ -device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x4,drive=libvirt-2-format,\ id=virtio-disk2 \ -object secret,id=libvirt-1-storage-httpcookie-secret0,\ -data=DrPR9NA6GKJb7qi1KbjHad3f3UIGTTDmAmOZHHv1F5w5T8rhnk3f+uSKStHe0J2O,\ +data=DrPR9NA6GKJb7qi1KbjHaealKEMVtOWUl2h3yvO5lgIh6cyLHemmlg+h9fcgwREA,\ keyid=masterKey0,iv=AAECAwQFBgcICQoLDA0ODw==,format=base64 \ -blockdev '{"driver":"https","url":"https://example.org:1234/test4.img",\ "sslverify":false,"cookie-secret":"libvirt-1-storage-httpcookie-secret0",\ diff --git a/tests/qemuxml2argvdata/disk-network-http.xml b/tests/qemuxml2argvdata/disk-network-http.xml index 20024c732e..93e6617433 100644 --- a/tests/qemuxml2argvdata/disk-network-http.xml +++ b/tests/qemuxml2argvdata/disk-network-http.xml @@ -35,7 +35,7 @@ <host name='example.org' port='1234'/> <cookies> <cookie name='test'>testcookievalue</cookie> - <cookie name='test2'>blurb</cookie> + <cookie name='test2'>"blurb"</cookie> </cookies> </source> <target dev='vdc' bus='virtio'/> @@ -47,7 +47,7 @@ <ssl verify='no'/> <cookies> <cookie name='test'>testcookievalue</cookie> - <cookie name='test2'>blurb</cookie> + <cookie name='test2'>"blurb"</cookie> </cookies> </source> <target dev='vdd' bus='virtio'/> diff --git a/tests/qemuxml2xmloutdata/disk-network-http.x86_64-latest.xml b/tests/qemuxml2xmloutdata/disk-network-http.x86_64-latest.xml index 9e78785d0d..cf36331286 100644 --- a/tests/qemuxml2xmloutdata/disk-network-http.x86_64-latest.xml +++ b/tests/qemuxml2xmloutdata/disk-network-http.x86_64-latest.xml @@ -41,7 +41,7 @@ <host name='example.org' port='1234'/> <cookies> <cookie name='test'>testcookievalue</cookie> - <cookie name='test2'>blurb</cookie> + <cookie name='test2'>"blurb"</cookie> </cookies> </source> <target dev='vdc' bus='virtio'/> @@ -54,7 +54,7 @@ <ssl verify='no'/> <cookies> <cookie name='test'>testcookievalue</cookie> - <cookie name='test2'>blurb</cookie> + <cookie name='test2'>"blurb"</cookie> </cookies> </source> <target dev='vdd' bus='virtio'/> -- 2.24.1

On a Wednesday in 2020, Peter Krempa wrote:
The validator didn't accept the quoted version of the cookie value. Add a test and fix the issue.
Peter Krempa (2): qemuxml2xmltest: Wire up 'disk-network-http' case virStorageSourceNetCookieValidate: Accept quoted cookie value
docs/schemas/domaincommon.rng | 2 +- src/util/virstoragefile.c | 19 ++++- .../disk-network-http.x86_64-latest.args | 4 +- tests/qemuxml2argvdata/disk-network-http.xml | 4 +- .../disk-network-http.x86_64-latest.xml | 71 +++++++++++++++++++ tests/qemuxml2xmltest.c | 2 + 6 files changed, 96 insertions(+), 6 deletions(-) create mode 100644 tests/qemuxml2xmloutdata/disk-network-http.x86_64-latest.xml
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano
participants (2)
-
Ján Tomko
-
Peter Krempa