diff mbox series

perf tools: Fix printable strings in python3 scripts

Message ID 20200928201135.3633850-1-jolsa@kernel.org
State New
Headers show
Series perf tools: Fix printable strings in python3 scripts | expand

Commit Message

Jiri Olsa Sept. 28, 2020, 8:11 p.m. UTC
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(-)

Comments

Arnaldo Carvalho de Melo Oct. 1, 2020, 3:12 p.m. UTC | #1
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
diff mbox series

Patch

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;
 	}