Currently, bhyveDomainEnsureAgent() returns successfully (with 0 return value) even in cases when the agent is not configured.
That happens because the bhyveConnectAgent() function does not fail if it cannot find the agent configuration. This might result in accessing the agent point at NULL. Fix by making bhyveConnectAgent() failing if the agent is not configured. Additionally, only call bhyveFindAgentConfig() when the agent is not configured to avoid unnecessary checks every time the agent is needed. Signed-off-by: Roman Bogorodskiy <[email protected]> --- src/bhyve/bhyve_process.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/bhyve/bhyve_process.c b/src/bhyve/bhyve_process.c index 92665419d4..e92bdeb416 100644 --- a/src/bhyve/bhyve_process.c +++ b/src/bhyve/bhyve_process.c @@ -243,14 +243,17 @@ bhyveConnectAgent(struct _bhyveConn *driver G_GNUC_UNUSED, virDomainObj *vm) { bhyveDomainObjPrivate *priv = vm->privateData; qemuAgent *agent = NULL; - virDomainChrDef *config = bhyveFindAgentConfig(vm->def); - - if (!config) - return 0; + virDomainChrDef *config = NULL; if (priv->agent) return 0; + if (!(config = bhyveFindAgentConfig(vm->def))) { + virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s", + _("QEMU guest agent is not configured")); + return -1; + } + agent = qemuAgentOpen(vm, config->source, virEventThreadGetContext(priv->eventThread), -- 2.52.0
