Skip to contentSkip to conversation

perf: header: Check read return

PATCH New James O. D. Hunt 1 participant 1 message Apr 7, 2025 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf: header: Check read return

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")
---
 tools/perf/util/header.c | 5 +++++
 1 file changed, 5 insertions(+)
tools/perf/util/header.c +5 -0
index e3cdc3b7b4ab..09dfd95e350c 100644
@@ -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));
Signature · 1 line
2.49.0