Skip to content

Commit 5a3d470

Browse files
ahunter6acmel
authored andcommitted
perf intel-pt: Fix segfault in intel_pt_print_info() with uClibc
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: 11fa7cb ("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>
1 parent e280396 commit 5a3d470

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

tools/perf/util/intel-pt.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4046,6 +4046,7 @@ static const char * const intel_pt_info_fmts[] = {
40464046
[INTEL_PT_SNAPSHOT_MODE] = " Snapshot mode %"PRId64"\n",
40474047
[INTEL_PT_PER_CPU_MMAPS] = " Per-cpu maps %"PRId64"\n",
40484048
[INTEL_PT_MTC_BIT] = " MTC bit %#"PRIx64"\n",
4049+
[INTEL_PT_MTC_FREQ_BITS] = " MTC freq bits %#"PRIx64"\n",
40494050
[INTEL_PT_TSC_CTC_N] = " TSC:CTC numerator %"PRIu64"\n",
40504051
[INTEL_PT_TSC_CTC_D] = " TSC:CTC denominator %"PRIu64"\n",
40514052
[INTEL_PT_CYC_BIT] = " CYC bit %#"PRIx64"\n",
@@ -4060,8 +4061,12 @@ static void intel_pt_print_info(__u64 *arr, int start, int finish)
40604061
if (!dump_trace)
40614062
return;
40624063

4063-
for (i = start; i <= finish; i++)
4064-
fprintf(stdout, intel_pt_info_fmts[i], arr[i]);
4064+
for (i = start; i <= finish; i++) {
4065+
const char *fmt = intel_pt_info_fmts[i];
4066+
4067+
if (fmt)
4068+
fprintf(stdout, fmt, arr[i]);
4069+
}
40654070
}
40664071

40674072
static void intel_pt_print_info_str(const char *name, const char *str)

0 commit comments

Comments
 (0)