* [PATCH] perf tools: Fix printable strings in python3 scripts
@ 2020-09-28 20:11 Jiri Olsa
2020-10-01 15:12 ` Arnaldo Carvalho de Melo
0 siblings, 1 reply; 2+ messages in thread
From: Jiri Olsa @ 2020-09-28 20:11 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: stable, Hagen Paul Pfeifer, lkml, Peter Zijlstra, Ingo Molnar,
Mark Rutland, Namhyung Kim, Alexander Shishkin, Michael Petlan
Hagen reported broken strings in python3 tracepoint scripts:
make PYTHON=python3
./perf record -e sched:sched_switch -a -- sleep 5
./perf script --gen-script py
./perf script -s ./perf-script.py
[..]
sched__sched_switch 7 563231.759525792 0 swapper \
prev_comm=bytearray(b'swapper/7\x00\x00\x00\x00\x00\x00\x00'), \
prev_pid=0, prev_prio=120, prev_state=, next_comm=bytearray(b'mutex-thread-co\x00'),
The problem is in is_printable_array function that does not take
zero byte into account and claim such string as not printable,
so the code will create byte array instead of string.
Cc: stable@vger.kernel.org
Fixes: 249de6e07458 ("perf script python: Fix string vs byte array resolving")
Tested-by: Hagen Paul Pfeifer <hagen@jauu.net>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
tools/perf/util/print_binary.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/perf/util/print_binary.c b/tools/perf/util/print_binary.c
index 599a1543871d..13fdc51c61d9 100644
--- a/tools/perf/util/print_binary.c
+++ b/tools/perf/util/print_binary.c
@@ -50,7 +50,7 @@ int is_printable_array(char *p, unsigned int len)
len--;
- for (i = 0; i < len; i++) {
+ for (i = 0; i < len && p[i]; i++) {
if (!isprint(p[i]) && !isspace(p[i]))
return 0;
}
--
2.26.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] perf tools: Fix printable strings in python3 scripts
2020-09-28 20:11 [PATCH] perf tools: Fix printable strings in python3 scripts Jiri Olsa
@ 2020-10-01 15:12 ` Arnaldo Carvalho de Melo
0 siblings, 0 replies; 2+ messages in thread
From: Arnaldo Carvalho de Melo @ 2020-10-01 15:12 UTC (permalink / raw)
To: Jiri Olsa
Cc: stable, Hagen Paul Pfeifer, lkml, Peter Zijlstra, Ingo Molnar,
Mark Rutland, Namhyung Kim, Alexander Shishkin, Michael Petlan
Em Mon, Sep 28, 2020 at 10:11:35PM +0200, Jiri Olsa escreveu:
> Hagen reported broken strings in python3 tracepoint scripts:
>
> make PYTHON=python3
> ./perf record -e sched:sched_switch -a -- sleep 5
> ./perf script --gen-script py
> ./perf script -s ./perf-script.py
>
> [..]
> sched__sched_switch 7 563231.759525792 0 swapper \
> prev_comm=bytearray(b'swapper/7\x00\x00\x00\x00\x00\x00\x00'), \
> prev_pid=0, prev_prio=120, prev_state=, next_comm=bytearray(b'mutex-thread-co\x00'),
>
> The problem is in is_printable_array function that does not take
> zero byte into account and claim such string as not printable,
> so the code will create byte array instead of string.
Thanks, tested and applied.
- Arnaldo
> Cc: stable@vger.kernel.org
> Fixes: 249de6e07458 ("perf script python: Fix string vs byte array resolving")
> Tested-by: Hagen Paul Pfeifer <hagen@jauu.net>
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---
> tools/perf/util/print_binary.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/perf/util/print_binary.c b/tools/perf/util/print_binary.c
> index 599a1543871d..13fdc51c61d9 100644
> --- a/tools/perf/util/print_binary.c
> +++ b/tools/perf/util/print_binary.c
> @@ -50,7 +50,7 @@ int is_printable_array(char *p, unsigned int len)
>
> len--;
>
> - for (i = 0; i < len; i++) {
> + for (i = 0; i < len && p[i]; i++) {
> if (!isprint(p[i]) && !isspace(p[i]))
> return 0;
> }
> --
> 2.26.2
>
--
- Arnaldo
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-10-01 15:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-28 20:11 [PATCH] perf tools: Fix printable strings in python3 scripts Jiri Olsa
2020-10-01 15:12 ` Arnaldo Carvalho de Melo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).