提交 3ed30062 编写于 作者: M Martin Kletzander

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=1058149Signed-off-by: NMartin Kletzander <mkletzan@redhat.com>
(cherry picked from commit 5b3492fa)
上级 88bdd6b9
......@@ -115,6 +115,8 @@ struct _qemuAgent {
qemuAgentEvent await_event;
};
static int qemuAgentCheckError(virJSONValuePtr cmd, virJSONValuePtr reply);
static virClassPtr qemuAgentClass;
static void qemuAgentDispose(void *obj);
......@@ -1006,6 +1008,7 @@ qemuAgentCommand(qemuAgentPtr mon,
}
} else {
*reply = msg.rxObject;
ret = qemuAgentCheckError(cmd, *reply);
}
}
......@@ -1274,9 +1277,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;
......@@ -1305,8 +1305,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) {
......@@ -1343,8 +1342,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) {
......@@ -1383,9 +1381,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;
......@@ -1416,9 +1411,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;
......@@ -1446,9 +1438,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;
......@@ -1469,8 +1458,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"))) {
......@@ -1578,8 +1566,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) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册