Skip to content

Commit fbb91da

Browse files
liu-song-6gregkh
authored andcommitted
perf script: Check session->header.env.arch before using it
commit 29c7755 upstream. 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 <songliubraving@fb.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: kernel-team@fb.com Cc: stable@vger.kernel.org Link: http://lore.kernel.org/lkml/20211004053238.514936-1-songliubraving@fb.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 6f41681 commit fbb91da

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

‎tools/perf/builtin-script.c‎

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

38223822
uname(&uts);
3823-
if (data.is_pipe || /* assume pipe_mode indicates native_arch */
3824-
!strcmp(uts.machine, session->header.env.arch) ||
3825-
(!strcmp(uts.machine, "x86_64") &&
3826-
!strcmp(session->header.env.arch, "i386")))
3823+
if (data.is_pipe) { /* Assume pipe_mode indicates native_arch */
38273824
native_arch = true;
3825+
} else if (session->header.env.arch) {
3826+
if (!strcmp(uts.machine, session->header.env.arch))
3827+
native_arch = true;
3828+
else if (!strcmp(uts.machine, "x86_64") &&
3829+
!strcmp(session->header.env.arch, "i386"))
3830+
native_arch = true;
3831+
}
38283832

38293833
script.session = session;
38303834
script__setup_sample_type(&script);

0 commit comments

Comments
 (0)