[PATCH v1 4/5] perf symbol: Check result when reading section headers

From: Namhyung Kim

Date: Sun Oct 18 2026 - 12:40:13 EST


Otherwise it may access uninitialized section header struct.

Reported-by: Sashiko <sashiko-bot@xxxxxxxxxx>
Closes: https://lore.kernel.org/r/sashiko-outbox-170233@xxxxxxxxxx
Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxxx>
---
tools/perf/util/symbol-elf.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
index 1e2716c6af45712a..00ea0e19020fb256 100644
--- a/tools/perf/util/symbol-elf.c
+++ b/tools/perf/util/symbol-elf.c
@@ -196,13 +196,15 @@ Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep,
while ((sec = elf_nextscn(elf, sec)) != NULL) {
char *str;

- gelf_getshdr(sec, shp);
+ if (!gelf_getshdr(sec, shp))
+ goto next;
str = elf_strptr(elf, ep->e_shstrndx, shp->sh_name);
if (str && !strcmp(name, str)) {
if (idx)
*idx = cnt;
return sec;
}
+next:
++cnt;
}

--
2.56.0.176.g3575e65682-goog