mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 09:17:52 +03:00
XML: escape strings where we should do it
There is a lot of places, were it's pretty easy for user to enter some characters that we need to escape to create a valid XML description. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1197580 Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
parent
ed8155eafb
commit
d091518b35
@ -682,9 +682,9 @@ virCapabilitiesDomainDataLookupInternal(virCapsPtr caps,
|
||||
virBufferAsprintf(&buf, "domaintype=%s ",
|
||||
virDomainVirtTypeToString(domaintype));
|
||||
if (emulator)
|
||||
virBufferAsprintf(&buf, "emulator=%s ", emulator);
|
||||
virBufferEscapeString(&buf, "emulator=%s ", emulator);
|
||||
if (machinetype)
|
||||
virBufferAsprintf(&buf, "machine=%s ", machinetype);
|
||||
virBufferEscapeString(&buf, "machine=%s ", machinetype);
|
||||
if (virBufferCurrentContent(&buf) &&
|
||||
!virBufferCurrentContent(&buf)[0])
|
||||
virBufferAsprintf(&buf, "%s", _("any configuration"));
|
||||
|
@ -544,17 +544,17 @@ virCPUDefFormatBuf(virBufferPtr buf,
|
||||
}
|
||||
virBufferAsprintf(buf, " fallback='%s'", fallback);
|
||||
if (def->vendor_id)
|
||||
virBufferAsprintf(buf, " vendor_id='%s'", def->vendor_id);
|
||||
virBufferEscapeString(buf, " vendor_id='%s'", def->vendor_id);
|
||||
}
|
||||
if (formatModel && def->model) {
|
||||
virBufferAsprintf(buf, ">%s</model>\n", def->model);
|
||||
virBufferEscapeString(buf, ">%s</model>\n", def->model);
|
||||
} else {
|
||||
virBufferAddLit(buf, "/>\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (formatModel && def->vendor)
|
||||
virBufferAsprintf(buf, "<vendor>%s</vendor>\n", def->vendor);
|
||||
virBufferEscapeString(buf, "<vendor>%s</vendor>\n", def->vendor);
|
||||
|
||||
if (def->sockets && def->cores && def->threads) {
|
||||
virBufferAddLit(buf, "<topology");
|
||||
|
@ -272,7 +272,7 @@ virDomainCapsFormatInternal(virBufferPtr buf,
|
||||
virBufferAddLit(buf, "<domainCapabilities>\n");
|
||||
virBufferAdjustIndent(buf, 2);
|
||||
|
||||
virBufferAsprintf(buf, "<path>%s</path>\n", caps->path);
|
||||
virBufferEscapeString(buf, "<path>%s</path>\n", caps->path);
|
||||
virBufferAsprintf(buf, "<domain>%s</domain>\n", virttype_str);
|
||||
virBufferAsprintf(buf, "<machine>%s</machine>\n", caps->machine);
|
||||
virBufferAsprintf(buf, "<arch>%s</arch>\n", arch_str);
|
||||
|
@ -3724,7 +3724,7 @@ virDomainDeviceInfoFormat(virBufferPtr buf,
|
||||
virBufferAsprintf(buf, " bar='%s'", rombar);
|
||||
}
|
||||
if (info->romfile)
|
||||
virBufferAsprintf(buf, " file='%s'", info->romfile);
|
||||
virBufferEscapeString(buf, " file='%s'", info->romfile);
|
||||
virBufferAddLit(buf, "/>\n");
|
||||
}
|
||||
|
||||
@ -17716,7 +17716,7 @@ virSecurityDeviceLabelDefFormat(virBufferPtr buf,
|
||||
virBufferAddLit(buf, "<seclabel");
|
||||
|
||||
if (def->model)
|
||||
virBufferAsprintf(buf, " model='%s'", def->model);
|
||||
virBufferEscapeString(buf, " model='%s'", def->model);
|
||||
|
||||
if (def->labelskip)
|
||||
virBufferAddLit(buf, " labelskip='yes'");
|
||||
@ -19250,50 +19250,46 @@ virDomainChrSourceDefFormat(virBufferPtr buf,
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_CHR_TYPE_NMDM:
|
||||
virBufferAsprintf(buf, "<source master='%s' slave='%s'/>\n",
|
||||
def->data.nmdm.master,
|
||||
def->data.nmdm.slave);
|
||||
virBufferEscapeString(buf, "<source master='%s' ",
|
||||
def->data.nmdm.master);
|
||||
virBufferEscapeString(buf, "slave='%s'/>\n", def->data.nmdm.slave);
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_CHR_TYPE_UDP:
|
||||
if (def->data.udp.bindService &&
|
||||
def->data.udp.bindHost) {
|
||||
virBufferAsprintf(buf,
|
||||
"<source mode='bind' host='%s' "
|
||||
"service='%s'/>\n",
|
||||
def->data.udp.bindHost,
|
||||
virBufferEscapeString(buf, "<source mode='bind' host='%s' ",
|
||||
def->data.udp.bindHost);
|
||||
virBufferEscapeString(buf, "service='%s'/>\n",
|
||||
def->data.udp.bindService);
|
||||
} else if (def->data.udp.bindHost) {
|
||||
virBufferAsprintf(buf, "<source mode='bind' host='%s'/>\n",
|
||||
virBufferEscapeString(buf, "<source mode='bind' host='%s'/>\n",
|
||||
def->data.udp.bindHost);
|
||||
} else if (def->data.udp.bindService) {
|
||||
virBufferAsprintf(buf, "<source mode='bind' service='%s'/>\n",
|
||||
virBufferEscapeString(buf, "<source mode='bind' service='%s'/>\n",
|
||||
def->data.udp.bindService);
|
||||
}
|
||||
|
||||
if (def->data.udp.connectService &&
|
||||
def->data.udp.connectHost) {
|
||||
virBufferAsprintf(buf,
|
||||
"<source mode='connect' host='%s' "
|
||||
"service='%s'/>\n",
|
||||
def->data.udp.connectHost,
|
||||
virBufferEscapeString(buf, "<source mode='connect' host='%s' ",
|
||||
def->data.udp.connectHost);
|
||||
virBufferEscapeString(buf, "service='%s'/>\n",
|
||||
def->data.udp.connectService);
|
||||
} else if (def->data.udp.connectHost) {
|
||||
virBufferAsprintf(buf, "<source mode='connect' host='%s'/>\n",
|
||||
virBufferEscapeString(buf, "<source mode='connect' host='%s'/>\n",
|
||||
def->data.udp.connectHost);
|
||||
} else if (def->data.udp.connectService) {
|
||||
virBufferAsprintf(buf,
|
||||
"<source mode='connect' service='%s'/>\n",
|
||||
virBufferEscapeString(buf, "<source mode='connect' service='%s'/>\n",
|
||||
def->data.udp.connectService);
|
||||
}
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_CHR_TYPE_TCP:
|
||||
virBufferAsprintf(buf,
|
||||
"<source mode='%s' host='%s' service='%s'/>\n",
|
||||
def->data.tcp.listen ? "bind" : "connect",
|
||||
def->data.tcp.host,
|
||||
def->data.tcp.service);
|
||||
virBufferAsprintf(buf, "<source mode='%s' ",
|
||||
def->data.tcp.listen ? "bind" : "connect");
|
||||
virBufferEscapeString(buf, "host='%s' ", def->data.tcp.host);
|
||||
virBufferEscapeString(buf, "service='%s'/>\n", def->data.tcp.service);
|
||||
virBufferAsprintf(buf, "<protocol type='%s'/>\n",
|
||||
virDomainChrTcpProtocolTypeToString(
|
||||
def->data.tcp.protocol));
|
||||
@ -19307,7 +19303,7 @@ virDomainChrSourceDefFormat(virBufferPtr buf,
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_CHR_TYPE_SPICEPORT:
|
||||
virBufferAsprintf(buf, "<source channel='%s'/>\n",
|
||||
virBufferEscapeString(buf, "<source channel='%s'/>\n",
|
||||
def->data.spiceport.channel);
|
||||
break;
|
||||
|
||||
|
@ -2422,21 +2422,20 @@ virNetworkDNSDefFormat(virBufferPtr buf,
|
||||
}
|
||||
|
||||
for (i = 0; i < def->ntxts; i++) {
|
||||
virBufferAsprintf(buf, "<txt name='%s' value='%s'/>\n",
|
||||
def->txts[i].name,
|
||||
def->txts[i].value);
|
||||
virBufferEscapeString(buf, "<txt name='%s' ", def->txts[i].name);
|
||||
virBufferEscapeString(buf, "value='%s'/>\n", def->txts[i].value);
|
||||
}
|
||||
|
||||
for (i = 0; i < def->nsrvs; i++) {
|
||||
if (def->srvs[i].service && def->srvs[i].protocol) {
|
||||
virBufferAsprintf(buf, "<srv service='%s' protocol='%s'",
|
||||
def->srvs[i].service,
|
||||
def->srvs[i].protocol);
|
||||
virBufferEscapeString(buf, "<srv service='%s' ",
|
||||
def->srvs[i].service);
|
||||
virBufferEscapeString(buf, "protocol='%s'", def->srvs[i].protocol);
|
||||
|
||||
if (def->srvs[i].domain)
|
||||
virBufferAsprintf(buf, " domain='%s'", def->srvs[i].domain);
|
||||
virBufferEscapeString(buf, " domain='%s'", def->srvs[i].domain);
|
||||
if (def->srvs[i].target)
|
||||
virBufferAsprintf(buf, " target='%s'", def->srvs[i].target);
|
||||
virBufferEscapeString(buf, " target='%s'", def->srvs[i].target);
|
||||
if (def->srvs[i].port)
|
||||
virBufferAsprintf(buf, " port='%d'", def->srvs[i].port);
|
||||
if (def->srvs[i].priority)
|
||||
@ -2455,7 +2454,7 @@ virNetworkDNSDefFormat(virBufferPtr buf,
|
||||
virBufferAsprintf(buf, "<host ip='%s'>\n", ip);
|
||||
virBufferAdjustIndent(buf, 2);
|
||||
for (j = 0; j < def->hosts[i].nnames; j++)
|
||||
virBufferAsprintf(buf, "<hostname>%s</hostname>\n",
|
||||
virBufferEscapeString(buf, "<hostname>%s</hostname>\n",
|
||||
def->hosts[i].names[j]);
|
||||
|
||||
virBufferAdjustIndent(buf, -2);
|
||||
|
@ -514,7 +514,7 @@ char *virNodeDeviceDefFormat(const virNodeDeviceDef *def)
|
||||
virBufferEscapeString(&buf, "<vendor>%s</vendor>\n",
|
||||
data->storage.vendor);
|
||||
if (data->storage.serial)
|
||||
virBufferAsprintf(&buf, "<serial>%s</serial>\n",
|
||||
virBufferEscapeString(&buf, "<serial>%s</serial>\n",
|
||||
data->storage.serial);
|
||||
if (data->storage.flags & VIR_NODE_DEV_CAP_STORAGE_REMOVABLE) {
|
||||
int avl = data->storage.flags &
|
||||
|
Loading…
Reference in New Issue
Block a user