]> git.proxmox.com Git - qemu.git/commitdiff
monitor: Catch printing to non-existent monitor
authorLuiz Capitulino <lcapitulino@redhat.com>
Mon, 14 Dec 2009 20:53:24 +0000 (18:53 -0200)
committerAnthony Liguori <aliguori@us.ibm.com>
Fri, 18 Dec 2009 17:26:27 +0000 (11:26 -0600)
The monitor_vprintf() function now touches the 'mon' pointer
before calling monitor_puts(), this causes block migration
to segfault as its functions call monitor_printf() with a
NULL 'mon'.

To fix the problem this commit moves the 'mon' NULL check
from monitor_puts() to monitor_vprintf().

This can potentially hide bugs, but for some reason this has
been the behavior for a long time.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
monitor.c

index b518cc4b555e268664a5c738c9c524510b71d66d..ebd0282ce4e217de25fbdeddd5c70a147cdce85c 100644 (file)
--- a/monitor.c
+++ b/monitor.c
@@ -177,9 +177,6 @@ static void monitor_puts(Monitor *mon, const char *str)
 {
     char c;
 
-    if (!mon)
-        return;
-
     for(;;) {
         c = *str++;
         if (c == '\0')
@@ -195,6 +192,9 @@ static void monitor_puts(Monitor *mon, const char *str)
 
 void monitor_vprintf(Monitor *mon, const char *fmt, va_list ap)
 {
+    if (!mon)
+        return;
+
     if (mon->mc && !mon->mc->print_enabled) {
         qemu_error_new(QERR_UNDEFINED_ERROR);
     } else {