[tip:perfcounters/core] perf_counter tools: fix infinite loop in perf-report on zeroed event records

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Commit-ID:  bad760089c1ef7fe525c0f268a4078b9cb483903
Gitweb:     http://git.kernel.org/tip/bad760089c1ef7fe525c0f268a4078b9cb483903
Author:     Ingo Molnar <mingo@xxxxxxx>
AuthorDate: Thu, 30 Apr 2009 14:14:37 +0200
Committer:  Ingo Molnar <mingo@xxxxxxx>
CommitDate: Thu, 30 Apr 2009 14:14:37 +0200

perf_counter tools: fix infinite loop in perf-report on zeroed event records

Bail out early if a record has zero size - we have no chance to make
reliable progress in that case. Print out the offset where this happens,
and print the number of bytes we missed out on.

Signed-off-by: Ingo Molnar <mingo@xxxxxxx>


---
 Documentation/perf_counter/perf-report.cc |   18 ++++++++++++++++--
 1 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/Documentation/perf_counter/perf-report.cc b/Documentation/perf_counter/perf-report.cc
index 1727317..933a075 100644
--- a/Documentation/perf_counter/perf-report.cc
+++ b/Documentation/perf_counter/perf-report.cc
@@ -13,6 +13,7 @@
 #include <ctype.h>
 #include <time.h>
 #include <getopt.h>
+#include <assert.h>
 
 #include <sys/ioctl.h>
 #include <sys/poll.h>
@@ -226,7 +227,7 @@ void load_kallsyms(void)
 	while (!feof(file)) {
 		uint64_t start;
 		char c;
-		char sym[1024];
+		char sym[1024000];
 
 		if (getline(&line, &n, file) < 0)
 			break;
@@ -416,12 +417,23 @@ more:
 
 	if (head + event->header.size >= page_size * mmap_window) {
 		unsigned long shift = page_size * (head / page_size);
+		int ret;
+
+		ret = munmap(buf, page_size * mmap_window);
+		assert(ret == 0);
 
-		munmap(buf, page_size * mmap_window);
 		offset += shift;
 		head -= shift;
 		goto remap;
 	}
+
+
+	if (!event->header.size) {
+		fprintf(stderr, "zero-sized event at file offset %ld\n", offset + head);
+		fprintf(stderr, "skipping %ld bytes of events.\n", stat.st_size - offset - head);
+		goto done;
+	}
+
 	head += event->header.size;
 
 	if (event->header.misc & PERF_EVENT_MISC_OVERFLOW) {
@@ -458,6 +470,8 @@ more:
 	if (offset + head < stat.st_size)
 		goto more;
 
+done:
+
 	close(input);
 
 	std::map<std::string, int>::iterator hi = hist.begin();
--
To unsubscribe from this list: send the line "unsubscribe linux-tip-commits" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Stable Commits]     [Linux Stable Kernel]     [Linux Kernel]     [Linux USB Devel]     [Linux Video &Media]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux