conf: Don't deref NULL actual network in virDomainNetGetActualHostdev()

In commit 991270db99 I've used virDomainNetGetActualHostdev() to get
the actual hostdev from a network when removing the network from the
list to avoid leaving the hostdev in the list. I didn't notice that this
function doesn't check if the actual network is allocated and
dereferences it. This crashes the daemon when cleaning up a domain
object in early startup phases when the actual network definition isn't
allocated. When the actual definition isn't present, the hostdev that
might correspond to it won't be present anyways so it's safe to return
NULL.

Thanks to Cole Robinson for noticing this problem.
This commit is contained in:
Peter Krempa 2013-09-04 17:32:12 +02:00
parent b78e8cb2ec
commit a3d24862df

View File

@ -17875,6 +17875,7 @@ virDomainNetGetActualHostdev(virDomainNetDefPtr iface)
if (iface->type == VIR_DOMAIN_NET_TYPE_HOSTDEV) if (iface->type == VIR_DOMAIN_NET_TYPE_HOSTDEV)
return &iface->data.hostdev.def; return &iface->data.hostdev.def;
if (iface->type == VIR_DOMAIN_NET_TYPE_NETWORK && if (iface->type == VIR_DOMAIN_NET_TYPE_NETWORK &&
iface->data.network.actual &&
iface->data.network.actual->type == VIR_DOMAIN_NET_TYPE_HOSTDEV) { iface->data.network.actual->type == VIR_DOMAIN_NET_TYPE_HOSTDEV) {
return &iface->data.network.actual->data.hostdev.def; return &iface->data.network.actual->data.hostdev.def;
} }