Skip to content

Commit 29c7755

Browse files
liu-song-6acmel
authored andcommitted
perf script: Check session->header.env.arch before using it
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]>
1 parent 0957294 commit 29c7755

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

tools/perf/builtin-script.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4039,11 +4039,15 @@ int cmd_script(int argc, const char **argv)
40394039
goto out_delete;
40404040

40414041
uname(&uts);
4042-
if (data.is_pipe || /* assume pipe_mode indicates native_arch */
4043-
!strcmp(uts.machine, session->header.env.arch) ||
4044-
(!strcmp(uts.machine, "x86_64") &&
4045-
!strcmp(session->header.env.arch, "i386")))
4042+
if (data.is_pipe) { /* Assume pipe_mode indicates native_arch */
40464043
native_arch = true;
4044+
} else if (session->header.env.arch) {
4045+
if (!strcmp(uts.machine, session->header.env.arch))
4046+
native_arch = true;
4047+
else if (!strcmp(uts.machine, "x86_64") &&
4048+
!strcmp(session->header.env.arch, "i386"))
4049+
native_arch = true;
4050+
}
40474051

40484052
script.session = session;
40494053
script__setup_sample_type(&script);

0 commit comments

Comments
 (0)