From patchwork Mon Sep 28 20:11:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Olsa X-Patchwork-Id: 291267 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 30A6EC4727C for ; Mon, 28 Sep 2020 20:18:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D432F206E5 for ; Mon, 28 Sep 2020 20:18:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601324288; bh=oIMY9eM6MaNGFAj03V/qzkFuzSWPhpDWuNff6PyYeug=; h=From:To:Cc:Subject:Date:List-ID:From; b=uQLlCv12dtNGW0WFNIduS/dxuW7ETpLds4lzT9cXpo4vBcvnZCO2xLKiBYkk3OWuC moA3tDtFh4yi+1m6iAOZxE4pi64BJa0QWRFUEaD0SqLZlO998BVTJt5AHnjMNAmooL +z1rkguIkrP49Hdnonvinrlq5+mgMCS//xu7qyA8= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726607AbgI1USG convert rfc822-to-8bit (ORCPT ); Mon, 28 Sep 2020 16:18:06 -0400 Received: from us-smtp-delivery-44.mimecast.com ([205.139.111.44]:28346 "EHLO us-smtp-delivery-44.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726424AbgI1USG (ORCPT ); Mon, 28 Sep 2020 16:18:06 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-234-81R2NBfkOjCvBz5ghBtP7g-1; Mon, 28 Sep 2020 16:11:41 -0400 X-MC-Unique: 81R2NBfkOjCvBz5ghBtP7g-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 512611074645; Mon, 28 Sep 2020 20:11:39 +0000 (UTC) Received: from krava.redhat.com (ovpn-112-124.ams2.redhat.com [10.36.112.124]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8680C78822; Mon, 28 Sep 2020 20:11:36 +0000 (UTC) From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: stable@vger.kernel.org, Hagen Paul Pfeifer , lkml , Peter Zijlstra , Ingo Molnar , Mark Rutland , Namhyung Kim , Alexander Shishkin , Michael Petlan Subject: [PATCH] perf tools: Fix printable strings in python3 scripts Date: Mon, 28 Sep 2020 22:11:35 +0200 Message-Id: <20200928201135.3633850-1-jolsa@kernel.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jolsa@kernel.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org 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 Signed-off-by: Jiri Olsa --- 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; }