Skip to content

Commit

Permalink
perf script: Check session->header.env.arch before using it
Browse files Browse the repository at this point in the history
When perf.data is not written cleanly, we would like to process existing
data as much as possible (please see f_header.data.size == 0 condition
in perf_session__read_header). However, perf.data with partial data may
crash perf. Specifically, we see crash in 'perf script' for NULL
session->header.env.arch.

Fix this by checking session->header.env.arch before using it to determine
native_arch. Also split the if condition so it is easier to read.

Committer notes:

If it is a pipe, we already assume is a native arch, so no need to check
session->header.env.arch.

Signed-off-by: Song Liu <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: [email protected]
Cc: [email protected]
Link: http://lore.kernel.org/lkml/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
  • Loading branch information
liu-song-6 authored and acmel committed Oct 31, 2021
1 parent 0957294 commit 29c7755
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions tools/perf/builtin-script.c
Original file line number Diff line number Diff line change
Expand Up @@ -4039,11 +4039,15 @@ int cmd_script(int argc, const char **argv)
goto out_delete;

uname(&uts);
if (data.is_pipe || /* assume pipe_mode indicates native_arch */
!strcmp(uts.machine, session->header.env.arch) ||
(!strcmp(uts.machine, "x86_64") &&
!strcmp(session->header.env.arch, "i386")))
if (data.is_pipe) { /* Assume pipe_mode indicates native_arch */
native_arch = true;
} else if (session->header.env.arch) {
if (!strcmp(uts.machine, session->header.env.arch))
native_arch = true;
else if (!strcmp(uts.machine, "x86_64") &&
!strcmp(session->header.env.arch, "i386"))
native_arch = true;
}

script.session = session;
script__setup_sample_type(&script);
Expand Down

0 comments on commit 29c7755

Please sign in to comment.