qemuBuildHostNetProps: Report proper errors for unhandled interface types

VIR_DOMAIN_NET_TYPE_NULL and VIR_DOMAIN_NET_TYPE_VDS are not implemented
for the qemu driver but the formatter code in 'qemuBuildHostNetProps'
didn't report an error for them and didn't even return from the function
when they were encountered.

This caused a crash in 'virJSONValueObjectAppendStringPrintf' which
does not tolerate NULL JSON object to append to when the unsupported
devices were used.

Properly report error when unhandled devices are encountered. This also
includes the case for VIR_DOMAIN_NET_TYPE_HOSTDEV, but that code path
should never be reached.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2175582
Fixes: bac6b266fb6a / 6457619d186
Fixes: 0225483adce
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2023-03-06 09:18:51 +01:00
parent 83a78633a7
commit f3a7338409

View File

@ -3995,8 +3995,14 @@ qemuBuildHostNetProps(virDomainObj *vm,
/* Should have been handled earlier via PCI/USB hotplug code. */
case VIR_DOMAIN_NET_TYPE_NULL:
case VIR_DOMAIN_NET_TYPE_VDS:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("network device type '%s' is not supported by this hypervisor"),
virDomainNetTypeToString(netType));
return NULL;
case VIR_DOMAIN_NET_TYPE_LAST:
break;
virReportEnumRangeError(virDomainNetType, netType);
return NULL;
}
if (virJSONValueObjectAppendStringPrintf(netprops, "id", "host%s", net->info.alias) < 0)