From patchwork Tue Jan 29 12:35:35 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 216513 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 664782C0099 for ; Tue, 29 Jan 2013 23:40:50 +1100 (EST) Received: from localhost ([::1]:36374 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U0AUa-0005xr-I0 for incoming@patchwork.ozlabs.org; Tue, 29 Jan 2013 07:40:48 -0500 Received: from eggs.gnu.org ([208.118.235.92]:55494) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U0AUP-0005xj-Ir for qemu-devel@nongnu.org; Tue, 29 Jan 2013 07:40:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U0AUO-0001MP-M2 for qemu-devel@nongnu.org; Tue, 29 Jan 2013 07:40:37 -0500 Received: from mx1.redhat.com ([209.132.183.28]:65035) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U0AUO-0001LQ-Ds for qemu-devel@nongnu.org; Tue, 29 Jan 2013 07:40:36 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r0TCZP4R001912 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 29 Jan 2013 07:35:25 -0500 Received: from doriath.home (ovpn-113-111.phx2.redhat.com [10.3.113.111]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r0TCZN5c028429; Tue, 29 Jan 2013 07:35:24 -0500 Date: Tue, 29 Jan 2013 10:35:35 -0200 From: Luiz Capitulino To: qemu-devel Message-ID: <20130129103535.13c23f71@doriath.home> Organization: Red Hat Mime-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: lilei@linux.vnet.ibm.com Subject: [Qemu-devel] [PATCH] hmp: hmp_memchar_read(): skip non-printable chars X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Otherwise we can get funny stuff printed and if the buffer contains a '\0' char it won't be fully printed. Signed-off-by: Luiz Capitulino --- hmp.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/hmp.c b/hmp.c index 249b89b..5bfc8bd 100644 --- a/hmp.c +++ b/hmp.c @@ -679,8 +679,10 @@ void hmp_memchar_read(Monitor *mon, const QDict *qdict) { uint32_t size = qdict_get_int(qdict, "size"); const char *chardev = qdict_get_str(qdict, "device"); + bool print_nl = false; MemCharRead *meminfo; Error *errp = NULL; + int i; meminfo = qmp_memchar_read(chardev, size, false, 0, &errp); if (errp) { @@ -689,8 +691,16 @@ void hmp_memchar_read(Monitor *mon, const QDict *qdict) return; } - if (meminfo->count > 0) { - monitor_printf(mon, "%s\n", meminfo->data); + for (i = 0; i < meminfo->count; i++) { + char c = meminfo->data[i]; + if (isprint(c) || c == '\n') { + monitor_printf(mon, "%c", c); + print_nl = true; + } + } + + if (print_nl) { + monitor_printf(mon, "\n"); } qapi_free_MemCharRead(meminfo);