From d0839bc1de52acd0902364565b6f9d030e591646 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Fri, 3 May 2019 15:44:49 +0200 Subject: [PATCH] PerfProfiler: Guard against some malformed input If there is no attribute we actually set the attribute to be the invalid one. Therefore an entry for the invalid attribute should exist. Also, cycles in the parent location IDs need to be avoided. Change-Id: Id1962744ef476ddad737cf108d9f9ab83a4eaf55 Reviewed-by: Milian Wolff --- src/plugins/perfprofiler/perfevent.h | 2 +- src/plugins/perfprofiler/perfeventtype.h | 1 + src/plugins/perfprofiler/perfprofilertracefile.cpp | 8 ++++++++ src/plugins/perfprofiler/perfprofilertracemanager.cpp | 2 ++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/plugins/perfprofiler/perfevent.h b/src/plugins/perfprofiler/perfevent.h index e57712a7224..dcee855e380 100644 --- a/src/plugins/perfprofiler/perfevent.h +++ b/src/plugins/perfprofiler/perfevent.h @@ -51,7 +51,7 @@ public: ThreadEndTypeId = -3, LostTypeId = -4, ContextSwitchTypeId = -5, - LastSpecialTypeId = -256 + LastSpecialTypeId = -6 }; int numAttributes() const { return m_values.length() + 1; } diff --git a/src/plugins/perfprofiler/perfeventtype.h b/src/plugins/perfprofiler/perfeventtype.h index 245b25991a9..457b6afeb2a 100644 --- a/src/plugins/perfprofiler/perfeventtype.h +++ b/src/plugins/perfprofiler/perfeventtype.h @@ -143,6 +143,7 @@ public: case ThreadEnd: case LostDefinition: case ContextSwitchDefinition: + case InvalidFeature: return true; default: return false; diff --git a/src/plugins/perfprofiler/perfprofilertracefile.cpp b/src/plugins/perfprofiler/perfprofilertracefile.cpp index cccdc6f7da0..c6ea883c797 100644 --- a/src/plugins/perfprofiler/perfprofilertracefile.cpp +++ b/src/plugins/perfprofiler/perfprofilertracefile.cpp @@ -177,6 +177,14 @@ void PerfProfilerTraceFile::readMessages(const QByteArray &buffer) case PerfEventType::LocationDefinition: { PerfEventType location(PerfEventType::LocationDefinition); dataStream >> id >> location; + for (int parent = location.location().parentLocationId; parent != -1; + parent = traceManager->location(parent).parentLocationId) { + if (parent == id) { + qWarning() << "A location cannot be its own parent location:" << id; + location = PerfEventType(PerfEventType::LocationDefinition); + break; + } + } traceManager->setEventType(id, std::move(location)); break; } diff --git a/src/plugins/perfprofiler/perfprofilertracemanager.cpp b/src/plugins/perfprofiler/perfprofilertracemanager.cpp index 6f93a4797dd..75c31af32a8 100644 --- a/src/plugins/perfprofiler/perfprofilertracemanager.cpp +++ b/src/plugins/perfprofiler/perfprofilertracemanager.cpp @@ -219,6 +219,8 @@ void PerfProfilerTraceManager::resetAttributes() tr("Samples lost"))); setEventType(PerfEvent::ContextSwitchTypeId, PerfEventType(PerfEventType::ContextSwitchDefinition, tr("Context switch"))); + setEventType(PerfEvent::LastSpecialTypeId, + PerfEventType(PerfEventType::InvalidFeature, tr("Invalid"))); } void PerfProfilerTraceManager::finalize()