[PATCH] perf: header: Check read return
From: James O. D. Hunt
Date: Mon Apr 07 2025 - 12:44:08 EST
Check the `readn()` return value in `read_attr()` if there are remaining
header bytes to read (previously, the return value was being ignored).
Fixes: 69996df486fc3 ("perf tools: Enable reading of perf.data files from different ABI rev")
Signed-off-by: James O. D. Hunt <james.o.hunt@xxxxxxxxx>
---
tools/perf/util/header.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index e3cdc3b7b4ab..09dfd95e350c 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -4161,6 +4161,11 @@ static int read_attr(int fd, struct perf_header *ph,
ptr += PERF_ATTR_SIZE_VER0;
ret = readn(fd, ptr, left);
+ if (ret <= 0) {
+ pr_debug("cannot read %zu remaining bytes of header attr\n",
+ left);
+ return -1;
+ }
}
/* read perf_file_section, ids are read in caller */
ret = readn(fd, &f_attr->ids, sizeof(f_attr->ids));
--
2.49.0