Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NKTvl-0001Uv-8J for qemu-devel@nongnu.org; Tue, 15 Dec 2009 04:42:57 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NKTve-0001Rk-Qt for qemu-devel@nongnu.org; Tue, 15 Dec 2009 04:42:55 -0500 Received: from [199.232.76.173] (port=35042 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NKTve-0001Re-KV for qemu-devel@nongnu.org; Tue, 15 Dec 2009 04:42:50 -0500 Received: from mx1.redhat.com ([209.132.183.28]:8367) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NKTve-0002gJ-4v for qemu-devel@nongnu.org; Tue, 15 Dec 2009 04:42:50 -0500 From: Markus Armbruster Subject: Re: [Qemu-devel] [PATCH 5/5] monitor: Catch printing to non-existent monitor References: <1260824004-2941-1-git-send-email-lcapitulino@redhat.com> <1260824004-2941-6-git-send-email-lcapitulino@redhat.com> Date: Tue, 15 Dec 2009 10:42:46 +0100 In-Reply-To: <1260824004-2941-6-git-send-email-lcapitulino@redhat.com> (Luiz Capitulino's message of "Mon, 14 Dec 2009 18:53:24 -0200") Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Luiz Capitulino Cc: aliguori@us.ibm.com, qemu-devel@nongnu.org Luiz Capitulino writes: > 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'. I figure this worked fine until commit 4a29a85d made monitor_vprintf() dereference 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 > --- > monitor.c | 6 +++--- > 1 files changed, 3 insertions(+), 3 deletions(-) > > diff --git a/monitor.c b/monitor.c > index b518cc4..ebd0282 100644 > --- 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 { There are no other callers of monitor_puts(), so removing the check there is okay. Before the code motion, we throw QERR_UNDEFINED_ERROR on monitor_vprintf(NULL, ...). Afterwards, we don't. Could you explain why that's okay?