From d3d5c1a00fcdbae92456a6e78a7d440880fff18a Mon Sep 17 00:00:00 2001 From: Ian Rogers Date: Fri, 6 Sep 2024 22:08:16 -0700 Subject: [PATCH] perf list: Avoid potential out of bounds memory read MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If a desc string is 0 length then -1 will be out of bounds, add a check. Signed-off-by: Ian Rogers Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Andi Kleen Cc: Athira Rajeev Cc: Benjamin Gray Cc: Changbin Du Cc: Clément Le Goffic Cc: Colin Ian King Cc: Dominique Martinet Cc: Dr. David Alan Gilbert Cc: Howard Chu Cc: Ingo Molnar Cc: James Clark Cc: Jing Zhang Cc: Jiri Olsa Cc: John Garry Cc: Junhao He Cc: Kan Liang Cc: Leo Yan Cc: Mark Rutland Cc: Mike Leach Cc: Namhyung Kim Cc: Oliver Upton Cc: Peter Zijlstra Cc: Ravi Bangoria Cc: Sandipan Das Cc: Sun Haiyong Cc: Tiezhu Yang Cc: Veronika Molnarova Cc: Weilin Wang Cc: Will Deacon Cc: Xu Yang Cc: Yang Jihong Cc: Yicong Yang Cc: Ze Gao Cc: linux-arm-kernel@lists.infradead.org Link: https://lore.kernel.org/r/20240907050830.6752-2-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-list.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c index 82cb4b1010aa..65b8cba324be 100644 --- a/tools/perf/builtin-list.c +++ b/tools/perf/builtin-list.c @@ -173,7 +173,7 @@ static void default_print_event(void *ps, const char *pmu_name, const char *topi if (pmu_name && strcmp(pmu_name, "default_core")) { desc_len = strlen(desc); desc_len = asprintf(&desc_with_unit, - desc[desc_len - 1] != '.' + desc_len > 0 && desc[desc_len - 1] != '.' ? "%s. Unit: %s" : "%s Unit: %s", desc, pmu_name); }