Error out on negative index values.
https://bugzilla.redhat.com/show_bug.cgi?id=981261
for (i = 0; i < def->ncontrollers; i++) {
cont = def->controllers[i];
- if (cont->idx > max_idx[cont->type])
+ if ((int) cont->idx > max_idx[cont->type])
max_idx[cont->type] = cont->idx;
}
idx = virXMLPropString(node, "index");
if (idx) {
- if (virStrToLong_i(idx, NULL, 10, &def->idx) < 0) {
+ if (virStrToLong_ui(idx, NULL, 10, &def->idx) < 0 ||
+ def->idx > INT_MAX) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Cannot parse controller index %s"), idx);
goto error;
}
virBufferAsprintf(buf,
- " <controller type='%s' index='%d'",
+ " <controller type='%s' index='%u'",
type, def->idx);
if (model) {
/* Stores the virtual disk controller configuration */
struct _virDomainControllerDef {
int type;
- int idx;
+ unsigned int idx;
int model; /* -1 == undef */
unsigned int queues;
union {
for (i = 0; i < def->ncontrollers; i++) {
if (def->controllers[i]->type == VIR_DOMAIN_CONTROLLER_TYPE_PCI) {
- if (def->controllers[i]->idx > max_idx)
+ if ((int) def->controllers[i]->idx > max_idx)
max_idx = def->controllers[i]->idx;
}
}
for (controller = 0; controller < def->ncontrollers; ++controller) {
if (def->controllers[controller]->type == VIR_DOMAIN_CONTROLLER_TYPE_SCSI) {
- if (def->controllers[controller]->idx < 0 ||
- def->controllers[controller]->idx > 3) {
+ if (def->controllers[controller]->idx > 3) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("SCSI controller index %d out of [0..3] range"),
def->controllers[controller]->idx);
--- /dev/null
+<domain type='qemu'>
+ <name>fdr-br</name>
+ <memory unit='KiB'>2097152</memory>
+ <currentMemory unit='KiB'>2097152</currentMemory>
+ <vcpu placement='static' cpuset='0-1'>2</vcpu>
+ <os>
+ <type arch='x86_64' machine='pc-1.2'>hvm</type>
+ <boot dev='hd'/>
+ </os>
+ <devices>
+ <emulator>/usr/libexec/qemu-kvm</emulator>
+ <controller type='pci' index='0' model='pci-root'/>
+ <controller type='pci' index='-1' model='pci-bridge'/>
+ </devices>
+</domain>
DO_TEST("mlock-off", QEMU_CAPS_MLOCK);
DO_TEST("mlock-unsupported", NONE);
+ DO_TEST_PARSE_ERROR("pci-bridge-negative-index-invalid",
+ QEMU_CAPS_DEVICE, QEMU_CAPS_DEVICE_PCI_BRIDGE);
+
virObjectUnref(driver.config);
virObjectUnref(driver.caps);
virObjectUnref(driver.xmlopt);