All of lore.kernel.org
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Steven Rostedt <rostedt@goodmis.org>,
	Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Cc: Frederic Weisbecker <fweisbec@gmail.com>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Ingo Molnar <mingo@kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Namhyung Kim <namhyung.kim@lge.com>
Subject: [PATCH RESEND 1/4] tools lib traceevent: Check string is really printable
Date: Wed, 27 Jun 2012 09:41:38 +0900	[thread overview]
Message-ID: <1340757701-10711-1-git-send-email-namhyung@kernel.org> (raw)

From: Namhyung Kim <namhyung.kim@lge.com>

When libtraceevent parses format fields, it assumes that
array of 1 byte is string but it's not always true. The
kvm_emulate_insn contains 15 u8 array of insn that contains
(binary) instructions. Thus when it's printed, it'll have
broken output like below:

  kvm_emulate_insn:     [FAILED TO PARSE] rip=3238197797 csbase=0 len=2 \
  insn=<89>P^]<B4>& flags=5 failed=0

With this patch:

  kvm_emulate_insn:     [FAILED TO PARSE] rip=3238197797 csbase=0 len=2 \
  insn=ARRAY[89, 10, 5d, c3, 8d, b4, 26, 00, 00, 00, 00, 55, 89, e5, 3e] flags=5 failed=0

Suggested-by: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/n/tip-ki5fuys70vig80gzsz3g58r1@git.kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/lib/traceevent/event-parse.c |   14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index 853b604b6240..eb195cbc841c 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -3655,6 +3655,16 @@ static void print_mac_arg(struct trace_seq *s, int mac, void *data, int size,
 	trace_seq_printf(s, fmt, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
 }
 
+static int is_printable_array(char *p, unsigned int len)
+{
+	unsigned int i;
+
+	for (i = 0; i < len && p[i]; i++)
+		if (!isprint(p[i]))
+			return 0;
+	return 1;
+}
+
 static void print_event_fields(struct trace_seq *s, void *data, int size,
 			       struct event_format *event)
 {
@@ -3674,7 +3684,8 @@ static void print_event_fields(struct trace_seq *s, void *data, int size,
 				len = offset >> 16;
 				offset &= 0xffff;
 			}
-			if (field->flags & FIELD_IS_STRING) {
+			if (field->flags & FIELD_IS_STRING &&
+			    is_printable_array(data + offset, len)) {
 				trace_seq_printf(s, "%s", (char *)data + offset);
 			} else {
 				trace_seq_puts(s, "ARRAY[");
@@ -3685,6 +3696,7 @@ static void print_event_fields(struct trace_seq *s, void *data, int size,
 							 *((unsigned char *)data + offset + i));
 				}
 				trace_seq_putc(s, ']');
+				field->flags &= ~FIELD_IS_STRING;
 			}
 		} else {
 			val = pevent_read_number(event->pevent, data + field->offset,
-- 
1.7.10.2


             reply	other threads:[~2012-06-27  0:45 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-27  0:41 Namhyung Kim [this message]
2012-06-27  0:41 ` [PATCH 2/4] KVM: Use __print_hex() for kvm_emulate_insn tracepoint Namhyung Kim
2012-06-27 12:49   ` Steven Rostedt
2012-06-27 12:54     ` Avi Kivity
2012-06-27 13:20       ` Steven Rostedt
2012-06-28  1:16         ` Namhyung Kim
2012-06-28  1:52           ` Steven Rostedt
2012-06-28  1:59             ` Namhyung Kim
2012-06-28  2:18               ` Steven Rostedt
2012-07-06 10:47   ` [tip:perf/core] tracing/kvm: " tip-bot for Namhyung Kim
2012-06-27  0:41 ` [PATCH 3/4] tools lib traceevent: Use local variable 'field' Namhyung Kim
2012-06-28 16:22   ` Arnaldo Carvalho de Melo
2012-07-06 10:54   ` [tip:perf/core] " tip-bot for Namhyung Kim
2012-06-27  0:41 ` [PATCH 4/4] tools lib traceevent: Add support for __print_hex() Namhyung Kim
2012-06-28 16:22   ` Arnaldo Carvalho de Melo
2012-07-06 10:55   ` [tip:perf/core] tools lib traceevent: Add support for __print_hex( ) tip-bot for Namhyung Kim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1340757701-10711-1-git-send-email-namhyung@kernel.org \
    --to=namhyung@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@ghostprotocols.net \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung.kim@lge.com \
    --cc=rostedt@goodmis.org \
    --subject='Re: [PATCH RESEND 1/4] tools lib traceevent: Check string is really printable' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.