From: Ian Rogers Date: Fri, 9 Feb 2024 20:49:46 +0000 (-0800) Subject: perf stat: Avoid metric-only segv X-Git-Tag: v5.10.214~91 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bae8577ea7ba4abab9edd331e84a7513b53ae1d8;p=thirdparty%2Fkernel%2Fstable.git perf stat: Avoid metric-only segv [ Upstream commit 2543947c77e0e224bda86b4e7220c2f6714da463 ] Cycles is recognized as part of a hard coded metric in stat-shadow.c, it may call print_metric_only with a NULL fmt string leading to a segfault. Handle the NULL fmt explicitly. Fixes: 088519f318be ("perf stat: Move the display functions to stat-display.c") Signed-off-by: Ian Rogers Reviewed-by: Kan Liang Cc: K Prateek Nayak Cc: James Clark Cc: Kaige Ye Cc: John Garry Signed-off-by: Namhyung Kim Link: https://lore.kernel.org/r/20240209204947.3873294-4-irogers@google.com Signed-off-by: Sasha Levin --- diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index 4688e39de52af..971fd77bd3e61 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -271,7 +271,7 @@ static void print_metric_only(struct perf_stat_config *config, if (color) mlen += strlen(color) + sizeof(PERF_COLOR_RESET) - 1; - color_snprintf(str, sizeof(str), color ?: "", fmt, val); + color_snprintf(str, sizeof(str), color ?: "", fmt ?: "", val); fprintf(out, "%*s ", mlen, str); }