diff --git a/src/util/virdnsmasq.c b/src/util/virdnsmasq.c index 6a2a2fbec6f0bbf2efc406c54fe5581cf19f6747..18e53a34b8016abbba5724251bfbbe65635bad1d 100644 --- a/src/util/virdnsmasq.c +++ b/src/util/virdnsmasq.c @@ -151,6 +151,7 @@ addnhostsNew(const char *name, const char *config_dir) { dnsmasqAddnHostsfile *addnhostsfile; + virBuffer buf = VIR_BUFFER_INITIALIZER; if (VIR_ALLOC(addnhostsfile) < 0) return NULL; @@ -158,13 +159,20 @@ addnhostsNew(const char *name, addnhostsfile->hosts = NULL; addnhostsfile->nhosts = 0; - if (virAsprintf(&addnhostsfile->path, "%s/%s.%s", config_dir, name, - DNSMASQ_ADDNHOSTSFILE_SUFFIX) < 0) + virBufferAsprintf(&buf, "%s", config_dir); + virBufferEscapeString(&buf, "/%s", name); + virBufferAsprintf(&buf, ".%s", DNSMASQ_ADDNHOSTSFILE_SUFFIX); + + if (virBufferCheckError(&buf) < 0) + goto error; + + if (!(addnhostsfile->path = virBufferContentAndReset(&buf))) goto error; return addnhostsfile; error: + virBufferFreeAndReset(&buf); addnhostsFree(addnhostsfile); return NULL; } @@ -357,6 +365,7 @@ hostsfileNew(const char *name, const char *config_dir) { dnsmasqHostsfile *hostsfile; + virBuffer buf = VIR_BUFFER_INITIALIZER; if (VIR_ALLOC(hostsfile) < 0) return NULL; @@ -364,13 +373,19 @@ hostsfileNew(const char *name, hostsfile->hosts = NULL; hostsfile->nhosts = 0; - if (virAsprintf(&hostsfile->path, "%s/%s.%s", config_dir, name, - DNSMASQ_HOSTSFILE_SUFFIX) < 0) - goto error; + virBufferAsprintf(&buf, "%s", config_dir); + virBufferEscapeString(&buf, "/%s", name); + virBufferAsprintf(&buf, ".%s", DNSMASQ_HOSTSFILE_SUFFIX); + if (virBufferCheckError(&buf) < 0) + goto error; + + if (!(hostsfile->path = virBufferContentAndReset(&buf))) + goto error; return hostsfile; error: + virBufferFreeAndReset(&buf); hostsfileFree(hostsfile); return NULL; } diff --git a/src/util/virpidfile.c b/src/util/virpidfile.c index 8144ff946af94a0e9ae8c8756e11481fa7c909e6..58ab29f77f2cfb8583447112dae77a07446bc627 100644 --- a/src/util/virpidfile.c +++ b/src/util/virpidfile.c @@ -45,12 +45,19 @@ VIR_LOG_INIT("util.pidfile"); char *virPidFileBuildPath(const char *dir, const char* name) { - char *pidfile; + virBuffer buf = VIR_BUFFER_INITIALIZER; - if (virAsprintf(&pidfile, "%s/%s.pid", dir, name) < 0) - return NULL; + virBufferAsprintf(&buf, "%s", dir); + virBufferEscapeString(&buf, "/%s.pid", name); - return pidfile; + if (virBufferCheckError(&buf) < 0) + goto error; + + return virBufferContentAndReset(&buf); + + error: + virBufferFreeAndReset(&buf); + return NULL; } diff --git a/tests/networkxml2confdata/nat-network-name-with-quotes.conf b/tests/networkxml2confdata/nat-network-name-with-quotes.conf new file mode 100644 index 0000000000000000000000000000000000000000..a1c839e74afa0a0622dcb33904d6d97cd8195c38 --- /dev/null +++ b/tests/networkxml2confdata/nat-network-name-with-quotes.conf @@ -0,0 +1,20 @@ +##WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE +##OVERWRITTEN AND LOST. Changes to this configuration should be made using: +## virsh net-edit default"with"quotes" +## or other application using the libvirt API. +## +## dnsmasq conf file created by libvirt +strict-order +except-interface=lo +bind-interfaces +listen-address=192.168.122.1 +listen-address=192.168.123.1 +listen-address=fc00:db8:ac10:fe01::1 +listen-address=fc00:db8:ac10:fd01::1 +listen-address=10.24.10.1 +srv-host=_name._tcp +dhcp-range=192.168.122.2,192.168.122.254 +dhcp-no-override +dhcp-lease-max=253 +dhcp-hostsfile=/var/lib/libvirt/dnsmasq/default"with"quotes".hostsfile +addn-hosts=/var/lib/libvirt/dnsmasq/default"with"quotes".addnhosts diff --git a/tests/networkxml2confdata/nat-network-name-with-quotes.xml b/tests/networkxml2confdata/nat-network-name-with-quotes.xml new file mode 100644 index 0000000000000000000000000000000000000000..eba75d2e2d18e5d6429ff55defaadfb835be5c40 --- /dev/null +++ b/tests/networkxml2confdata/nat-network-name-with-quotes.xml @@ -0,0 +1,26 @@ + + default"with"quotes" + 81ff0d90-c91e-6742-64da-4a736edb9a9b + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/networkxml2conftest.c b/tests/networkxml2conftest.c index fe95e8c8c280a1db6cdecac004a914d5c0d6fabc..a5f271167e66fb2a702f36f452d8cbdd3dde5a1a 100644 --- a/tests/networkxml2conftest.c +++ b/tests/networkxml2conftest.c @@ -115,6 +115,7 @@ mymain(void) DO_TEST("netboot-network", restricted); DO_TEST("netboot-proxy-network", restricted); DO_TEST("nat-network-dns-srv-record-minimal", restricted); + DO_TEST("nat-network-name-with-quotes", restricted); DO_TEST("routed-network", full); DO_TEST("nat-network", dhcpv6); DO_TEST("nat-network-dns-txt-record", full);