Ensure unexpected values are dealt with correctly, that
is by invoking virReportEnumRangeError() and immediately
returning a negative value to the caller.
Signed-off-by: Andrea Bolognani <abologna(a)redhat.com>
---
src/qemu/qemu_command.c | 10 ++++++++--
src/qemu/qemu_domain.c | 1 +
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 5bf6c704e0..fcc6caf42f 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -6961,8 +6961,12 @@ qemuBuildIOMMUCommandLine(virCommandPtr cmd,
virBufferAsprintf(&opts, ",device-iotlb=%s",
virTristateSwitchTypeToString(iommu->iotlb));
}
- case VIR_DOMAIN_IOMMU_MODEL_LAST:
break;
+
+ case VIR_DOMAIN_IOMMU_MODEL_LAST:
+ default:
+ virReportEnumRangeError(virDomainIOMMUModel, iommu->model);
+ return -1;
}
virCommandAddArg(cmd, "-device");
virCommandAddArgBuffer(cmd, &opts);
@@ -7609,7 +7613,9 @@ qemuBuildMachineCommandLine(virCommandPtr cmd,
virBufferAddLit(&buf, ",iommu=on");
break;
case VIR_DOMAIN_IOMMU_MODEL_LAST:
- break;
+ default:
+ virReportEnumRangeError(virDomainIOMMUModel, def->iommu->model);
+ return -1;
}
}
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index e50e84a3b2..366ebe1604 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -6138,6 +6138,7 @@ qemuDomainDeviceDefValidateIOMMU(const virDomainIOMMUDef *iommu,
case VIR_DOMAIN_IOMMU_MODEL_LAST:
default:
virReportEnumRangeError(virDomainIOMMUModel, iommu->model);
+ return -1;
}
return 0;
--
2.21.0