qemu: Escape snapshot name passed to {save,load,del}vm

This commit is contained in:
Jiri Denemark 2011-03-09 21:47:06 +01:00
parent 89241fe0d1
commit 81711cee34

View File

@ -2566,13 +2566,15 @@ cleanup:
int qemuMonitorTextCreateSnapshot(qemuMonitorPtr mon, const char *name) int qemuMonitorTextCreateSnapshot(qemuMonitorPtr mon, const char *name)
{ {
char *cmd; char *cmd = NULL;
char *reply = NULL; char *reply = NULL;
int ret = -1; int ret = -1;
char *safename;
if (virAsprintf(&cmd, "savevm \"%s\"", name) < 0) { if (!(safename = qemuMonitorEscapeArg(name)) ||
virAsprintf(&cmd, "savevm \"%s\"", safename) < 0) {
virReportOOMError(); virReportOOMError();
return -1; goto cleanup;
} }
if (qemuMonitorHMPCommand(mon, cmd, &reply)) { if (qemuMonitorHMPCommand(mon, cmd, &reply)) {
@ -2604,6 +2606,7 @@ int qemuMonitorTextCreateSnapshot(qemuMonitorPtr mon, const char *name)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(safename);
VIR_FREE(cmd); VIR_FREE(cmd);
VIR_FREE(reply); VIR_FREE(reply);
return ret; return ret;
@ -2611,13 +2614,15 @@ cleanup:
int qemuMonitorTextLoadSnapshot(qemuMonitorPtr mon, const char *name) int qemuMonitorTextLoadSnapshot(qemuMonitorPtr mon, const char *name)
{ {
char *cmd; char *cmd = NULL;
char *reply = NULL; char *reply = NULL;
int ret = -1; int ret = -1;
char *safename;
if (virAsprintf(&cmd, "loadvm \"%s\"", name) < 0) { if (!(safename = qemuMonitorEscapeArg(name)) ||
virAsprintf(&cmd, "loadvm \"%s\"", safename) < 0) {
virReportOOMError(); virReportOOMError();
return -1; goto cleanup;
} }
if (qemuMonitorHMPCommand(mon, cmd, &reply)) { if (qemuMonitorHMPCommand(mon, cmd, &reply)) {
@ -2660,6 +2665,7 @@ int qemuMonitorTextLoadSnapshot(qemuMonitorPtr mon, const char *name)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(safename);
VIR_FREE(cmd); VIR_FREE(cmd);
VIR_FREE(reply); VIR_FREE(reply);
return ret; return ret;
@ -2667,13 +2673,15 @@ cleanup:
int qemuMonitorTextDeleteSnapshot(qemuMonitorPtr mon, const char *name) int qemuMonitorTextDeleteSnapshot(qemuMonitorPtr mon, const char *name)
{ {
char *cmd; char *cmd = NULL;
char *reply = NULL; char *reply = NULL;
int ret = -1; int ret = -1;
char *safename;
if (virAsprintf(&cmd, "delvm \"%s\"", name) < 0) { if (!(safename = qemuMonitorEscapeArg(name)) ||
virAsprintf(&cmd, "delvm \"%s\"", safename) < 0) {
virReportOOMError(); virReportOOMError();
return -1; goto cleanup;
} }
if (qemuMonitorHMPCommand(mon, cmd, &reply)) { if (qemuMonitorHMPCommand(mon, cmd, &reply)) {
qemuReportError(VIR_ERR_OPERATION_FAILED, qemuReportError(VIR_ERR_OPERATION_FAILED,
@ -2700,6 +2708,7 @@ int qemuMonitorTextDeleteSnapshot(qemuMonitorPtr mon, const char *name)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(safename);
VIR_FREE(cmd); VIR_FREE(cmd);
VIR_FREE(reply); VIR_FREE(reply);
return ret; return ret;