Commit 0f21decf authored by Ulf Hermann's avatar Ulf Hermann

QmlProfiler: Correctly handle invalid message types

We might get malformed events from the application. Clamp message and
range types into the allowed enum values when reading and reset the
event data when reading an invalid event.

Change-Id: Id76a3a8b8ed9378f9fb1acf15cf46d20758ca030
Reviewed-by: default avatarMilian Wolff <milian.wolff@kdab.com>
parent 9cdb0ec2
......@@ -108,7 +108,7 @@ static QString qmlTypeAsString(Message message, RangeType rangeType)
{
if (rangeType < MaximumRangeType)
return _(RANGE_TYPE_STRINGS[rangeType]);
else if (message != MaximumMessage)
else if (message < MaximumMessage)
return _(MESSAGE_STRINGS[message]);
else
return QString::number((int)rangeType);
......
......@@ -36,10 +36,15 @@ QDataStream &operator>>(QDataStream &stream, QmlTypedEvent &event)
stream >> time >> messageType;
if (messageType < 0 || messageType > MaximumMessage)
messageType = MaximumMessage;
RangeType rangeType = MaximumRangeType;
if (!stream.atEnd()) {
stream >> subtype;
rangeType = static_cast<RangeType>(subtype);
if (rangeType < 0 || rangeType > MaximumRangeType)
rangeType = MaximumRangeType;
} else {
subtype = -1;
}
......@@ -180,6 +185,7 @@ QDataStream &operator>>(QDataStream &stream, QmlTypedEvent &event)
break;
}
default:
event.event.setNumbers<char>({});
event.type = QmlEventType(static_cast<Message>(messageType), MaximumRangeType, subtype);
break;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment