From patchwork Tue Jan 29 12:35:35 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: hmp: hmp_memchar_read(): skip non-printable chars Date: Tue, 29 Jan 2013 02:35:35 -0000 From: Luiz Capitulino X-Patchwork-Id: 216513 Message-Id: <20130129103535.13c23f71@doriath.home> To: qemu-devel Cc: lilei@linux.vnet.ibm.com 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);