diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index 86ec6c720f0f8f9be384147bdecba1c9cff3ffa6..f56158fb4dc9d09d68281b33f733473688bc56ca 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c @@ -921,6 +921,7 @@ int filename__read_build_id(const char *filename, void *bf, size_t size) GElf_Shdr shdr; Elf_Data *data; Elf_Scn *sec; + Elf_Kind ek; void *ptr; Elf *elf; @@ -937,6 +938,10 @@ int filename__read_build_id(const char *filename, void *bf, size_t size) goto out_close; } + ek = elf_kind(elf); + if (ek != ELF_K_ELF) + goto out_elf_end; + if (gelf_getehdr(elf, &ehdr) == NULL) { pr_err("%s: cannot get elf header.\n", __func__); goto out_elf_end;