perf intel-pt: Fix segfault in intel_pt_print_info() with uClibc
authorAdrian Hunter <adrian.hunter@intel.com>
Wed, 12 Oct 2022 08:22:58 +0000 (11:22 +0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Sat, 15 Oct 2022 13:13:16 +0000 (10:13 -0300)
uClibc segfaulted because NULL was passed as the format to fprintf().

That happened because one of the format strings was missing and
intel_pt_print_info() didn't check that before calling fprintf().

Add the missing format string, and check format is not NULL before calling
fprintf().

Fixes: 11fa7cb86b56d361 ("perf tools: Pass Intel PT information for decoding MTC and CYC")
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20221012082259.22394-2-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/intel-pt.c

index b34cb3dec1aac0afd82c8754c76d04f2d7f7bc77..e3548ddef2545e25b787fc599c2b4a15df908331 100644 (file)
@@ -4046,6 +4046,7 @@ static const char * const intel_pt_info_fmts[] = {
        [INTEL_PT_SNAPSHOT_MODE]        = "  Snapshot mode       %"PRId64"\n",
        [INTEL_PT_PER_CPU_MMAPS]        = "  Per-cpu maps        %"PRId64"\n",
        [INTEL_PT_MTC_BIT]              = "  MTC bit             %#"PRIx64"\n",
+       [INTEL_PT_MTC_FREQ_BITS]        = "  MTC freq bits       %#"PRIx64"\n",
        [INTEL_PT_TSC_CTC_N]            = "  TSC:CTC numerator   %"PRIu64"\n",
        [INTEL_PT_TSC_CTC_D]            = "  TSC:CTC denominator %"PRIu64"\n",
        [INTEL_PT_CYC_BIT]              = "  CYC bit             %#"PRIx64"\n",
@@ -4060,8 +4061,12 @@ static void intel_pt_print_info(__u64 *arr, int start, int finish)
        if (!dump_trace)
                return;
 
-       for (i = start; i <= finish; i++)
-               fprintf(stdout, intel_pt_info_fmts[i], arr[i]);
+       for (i = start; i <= finish; i++) {
+               const char *fmt = intel_pt_info_fmts[i];
+
+               if (fmt)
+                       fprintf(stdout, fmt, arr[i]);
+       }
 }
 
 static void intel_pt_print_info_str(const char *name, const char *str)