]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Sanitize qemu monitor reads.
authorCole Robinson <crobinso@redhat.com>
Tue, 16 Dec 2008 22:34:13 +0000 (22:34 +0000)
committerCole Robinson <crobinso@redhat.com>
Tue, 16 Dec 2008 22:34:13 +0000 (22:34 +0000)
ChangeLog
src/qemu_driver.c

index cd379edeb9951a3c12b18005acb5fb1f6274b55f..7a6741ca4b1d96716cec4a0d4773d3fde56045ff 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
index 5f6fbd19a90e06b2c98f129e9bfb1641fd53671d..40016cb0176dca5a4b380c103634cb4d71be515b 100644 (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"));