diff --git a/ChangeLog b/ChangeLog index cd379edeb9..7a6741ca4b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Tue Dec 16 17:26:49 EST 2008 Cole Robinson + + * src/qemu_driver.c: Sanitize qemu monitor reads. + Mon Dec 15 21:05:56 CET 2008 Guido Günther Add virAsprintf as safer asprintf helper diff --git a/src/qemu_driver.c b/src/qemu_driver.c index 5f6fbd19a9..40016cb017 100644 --- a/src/qemu_driver.c +++ b/src/qemu_driver.c @@ -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"));