diff options
author | Martin Kletzander <mkletzan@redhat.com> | 2014-04-01 14:58:56 +0200 |
---|---|---|
committer | Martin Kletzander <mkletzan@redhat.com> | 2014-04-09 18:45:22 +0200 |
commit | 32978fdc1d18ecdf059b6b3655816599c3c4fd7b (patch) | |
tree | 27e80b9b8ed563e3e5498dd5535041744d675b48 | |
parent | 57170e154e60969716714066bf6ea7a9804e0e5f (diff) | |
download | libvirt-32978fdc1d18ecdf059b6b3655816599c3c4fd7b.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)
-rw-r--r-- | src/qemu/qemu_agent.c | 27 |
1 files changed, 7 insertions, 20 deletions
diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index 2cd0ccc709..85ac25644c 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); @@ -1005,6 +1007,7 @@ qemuAgentCommand(qemuAgentPtr mon, } } else { *reply = msg.rxObject; + ret = qemuAgentCheckError(cmd, *reply); } } @@ -1273,9 +1276,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; @@ -1304,8 +1304,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) { @@ -1342,8 +1341,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) { @@ -1382,9 +1380,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; @@ -1415,9 +1410,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; @@ -1445,9 +1437,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; @@ -1468,8 +1457,7 @@ qemuAgentGetVCPUs(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 (!(data = virJSONValueObjectGet(reply, "return"))) { @@ -1577,8 +1565,7 @@ qemuAgentSetVCPUs(qemuAgentPtr mon, cpus = NULL; 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) { |