summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Kletzander <mkletzan@redhat.com>2014-04-01 14:58:56 +0200
committerMartin Kletzander <mkletzan@redhat.com>2014-04-09 18:35:01 +0200
commit8f69204d4aa589e4cc0771380cc7117eac4a3de7 (patch)
tree0b61e76ac600dd7a3f89f7e4d2faf49751f2e49e
parent129862c58deba87c942116aea1e2a3a4bd19d34a (diff)
downloadlibvirt-8f69204d4aa589e4cc0771380cc7117eac4a3de7.tar.gz
qemu: cleanup error checking on agent replies
On all the places where qemuAgentComand() was called, we did a check for errors in the reply. Unfortunately, some of the places called qemuAgentCheckError() without checking for non-null reply which might have resulted in a crash. So this patch makes the error-checking part of qemuAgentCommand() itself, which: a) makes it look better, b) makes the check mandatory and, most importantly, c) checks for the errors if and only if it is appropriate. This actually fixes a potential crashers when qemuAgentComand() returned 0, but reply was NULL. Having said that, it *should* fix the following bug: https://bugzilla.redhat.com/show_bug.cgi?id=1058149 Signed-off-by: Martin Kletzander <mkletzan@redhat.com> (cherry picked from commit 5b3492fadb6bfddd370e263bf8a6953b1b26116f) Conflicts: src/qemu/qemu_agent.c -- vCPU functions (3099c063)
-rw-r--r--src/qemu/qemu_agent.c21
1 files changed, 5 insertions, 16 deletions
diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
index 00fe13f598..60bbe6badd 100644
--- a/src/qemu/qemu_agent.c
+++ b/src/qemu/qemu_agent.c
@@ -115,6 +115,8 @@ struct _qemuAgent {
qemuAgentEvent await_event;
};
+static int qemuAgentCheckError(virJSONValuePtr cmd, virJSONValuePtr reply);
+
static virClassPtr qemuAgentClass;
static void qemuAgentDispose(void *obj);
@@ -1014,6 +1016,7 @@ qemuAgentCommand(qemuAgentPtr mon,
}
} else {
*reply = msg.rxObject;
+ ret = qemuAgentCheckError(cmd, *reply);
}
}
@@ -1284,9 +1287,6 @@ int qemuAgentShutdown(qemuAgentPtr mon,
ret = qemuAgentCommand(mon, cmd, &reply,
VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK);
- if (reply && ret == 0)
- ret = qemuAgentCheckError(cmd, reply);
-
virJSONValueFree(cmd);
virJSONValueFree(reply);
return ret;
@@ -1315,8 +1315,7 @@ int qemuAgentFSFreeze(qemuAgentPtr mon)
return -1;
if (qemuAgentCommand(mon, cmd, &reply,
- VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK) < 0 ||
- qemuAgentCheckError(cmd, reply) < 0)
+ VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK) < 0)
goto cleanup;
if (virJSONValueObjectGetNumberInt(reply, "return", &ret) < 0) {
@@ -1353,8 +1352,7 @@ int qemuAgentFSThaw(qemuAgentPtr mon)
return -1;
if (qemuAgentCommand(mon, cmd, &reply,
- VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK) < 0 ||
- qemuAgentCheckError(cmd, reply) < 0)
+ VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK) < 0)
goto cleanup;
if (virJSONValueObjectGetNumberInt(reply, "return", &ret) < 0) {
@@ -1393,9 +1391,6 @@ qemuAgentSuspend(qemuAgentPtr mon,
ret = qemuAgentCommand(mon, cmd, &reply,
VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK);
- if (reply && ret == 0)
- ret = qemuAgentCheckError(cmd, reply);
-
virJSONValueFree(cmd);
virJSONValueFree(reply);
return ret;
@@ -1426,9 +1421,6 @@ qemuAgentArbitraryCommand(qemuAgentPtr mon,
if ((ret = qemuAgentCommand(mon, cmd, &reply, timeout)) < 0)
goto cleanup;
- if ((ret = qemuAgentCheckError(cmd, reply)) < 0)
- goto cleanup;
-
if (!(*result = virJSONValueToString(reply, false)))
ret = -1;
@@ -1456,9 +1448,6 @@ qemuAgentFSTrim(qemuAgentPtr mon,
ret = qemuAgentCommand(mon, cmd, &reply,
VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK);
- if (reply && ret == 0)
- ret = qemuAgentCheckError(cmd, reply);
-
virJSONValueFree(cmd);
virJSONValueFree(reply);
return ret;