Sanitize qemu monitor reads.

This commit is contained in:
Cole Robinson 2008-12-16 22:34:13 +00:00
parent 36c612b21c
commit 0e459cbdfb
2 changed files with 24 additions and 4 deletions

View File

@ -1,3 +1,7 @@
Tue Dec 16 17:26:49 EST 2008 Cole Robinson <crobinso@redhat.com>
* src/qemu_driver.c: Sanitize qemu monitor reads.
Mon Dec 15 21:05:56 CET 2008 Guido Günther <agx@sigxcpu.org>
Add virAsprintf as safer asprintf helper

View File

@ -1198,7 +1198,23 @@ qemudMonitorCommand (const virDomainObjPtr vm,
/* Look for QEMU prompt to indicate completion */
if (buf && ((tmp = strstr(buf, "\n(qemu) ")) != NULL)) {
tmp[0] = '\0';
char *commptr = NULL, *nlptr = NULL;
/* Preserve the newline */
tmp[1] = '\0';
/* The monitor doesn't dump clean output after we have written to
* it. Every character we write dumps a bunch of useless stuff,
* so the result looks like "cXcoXcomXcommXcommaXcommanXcommand"
* Try to throw away everything before the first full command
* occurence, and inbetween the command and the newline starting
* the response
*/
if ((commptr = strstr(buf, cmd)))
memmove(buf, commptr, strlen(commptr)+1);
if ((nlptr = strchr(buf, '\n')))
memmove(buf+strlen(cmd), nlptr, strlen(nlptr)+1);
break;
}
pollagain:
@ -2919,7 +2935,7 @@ static int qemudDomainChangeEjectableMedia(virConnectPtr conn,
if (qemudMonitorCommand(vm, cmd, &reply) < 0) {
qemudReportError(conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
"%s", _("cannot change cdrom media"));
"%s", _("could not change cdrom media"));
VIR_FREE(cmd);
return -1;
}
@ -2930,7 +2946,7 @@ static int qemudDomainChangeEjectableMedia(virConnectPtr conn,
DEBUG ("ejectable media change reply: %s", reply);
if (strstr(reply, "\ndevice ")) {
qemudReportError (conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
"%s", _("changing cdrom media failed"));
_("changing cdrom media failed: %s"), reply);
VIR_FREE(reply);
VIR_FREE(cmd);
return -1;
@ -3468,7 +3484,7 @@ qemudDomainBlockStats (virDomainPtr dom,
* unlikely to be the name of a block device, we can use this
* to detect if qemu supports the command.
*/
if (STRPREFIX (info, "info ")) {
if (strstr(info, "\ninfo ")) {
qemudReportError (dom->conn, dom, NULL, VIR_ERR_NO_SUPPORT,
"%s",
_("'info blockstats' not supported by this qemu"));