mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Arun Kalyanasundaram <arunkaly@google.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>, linux-kernel@vger.kernel.org
Cc: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Arun Kalyanasundaram <arunkaly@google.com>,
	Jiri Olsa <jolsa@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	"David S . Miller" <davem@davemloft.net>,
	SeongJae Park <sj38.park@gmail.com>,
	davidcc@google.com, Stephane Eranian <eranian@google.com>,
	Arun Kalyanasundaram <arunkalys@gmail.com>
Subject: [PATCH 1/1] perf script python: Garbled text in tracepoint fields
Date: Fri, 11 Aug 2017 13:38:09 -0700	[thread overview]
Message-ID: <20170811203809.120130-2-arunkaly@google.com> (raw)
In-Reply-To: <20170811203809.120130-1-arunkaly@google.com>

Pass the exact length of the string to is_printable_array instead of the
entire field size.

Signed-off-by: Arun Kalyanasundaram <arunkaly@google.com>
---
 tools/perf/util/scripting-engines/trace-event-python.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
index c7187f067d31..45cc0c6635bb 100644
--- a/tools/perf/util/scripting-engines/trace-event-python.c
+++ b/tools/perf/util/scripting-engines/trace-event-python.c
@@ -601,6 +601,7 @@ static void python_process_tracepoint(struct perf_sample *sample,
 	for (field = event->format.fields; field; field = field->next) {
 		unsigned int offset, len;
 		unsigned long long val;
+		char *end_ptr = NULL;
 
 		if (field->flags & FIELD_IS_ARRAY) {
 			offset = field->offset;
@@ -612,8 +613,12 @@ static void python_process_tracepoint(struct perf_sample *sample,
 				len     = offset >> 16;
 				offset &= 0xffff;
 			}
-			if (field->flags & FIELD_IS_STRING &&
-			    is_printable_array(data + offset, len)) {
+			/* field may contain unused chars after the null char */
+			if (field->flags & FIELD_IS_STRING)
+				end_ptr = memchr(data + offset, '\0', len);
+			if (end_ptr &&
+			    is_printable_array(data + offset,
+				(int)(end_ptr - ((char *)data + offset)) + 1)) {
 				obj = PyString_FromString((char *) data + offset);
 			} else {
 				obj = PyByteArray_FromStringAndSize((const char *) data + offset, len);
-- 
2.14.0.434.g98096fd7a8-goog

      reply	other threads:[~2017-08-11 20:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-11 20:38 [PATCH 0/1] " Arun Kalyanasundaram
2017-08-11 20:38 ` Arun Kalyanasundaram [this message]

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=20170811203809.120130-2-arunkaly@google.com \
    --to=arunkaly@google.com \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=arunkalys@gmail.com \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=davidcc@google.com \
    --cc=eranian@google.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=sj38.park@gmail.com \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®