From d214c56e43160cb121e1caab96f0e457f9bfde99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4=C3=A4tt=C3=A4?= Date: Wed, 31 May 2023 09:45:00 +0300 Subject: [PATCH] CTF: Properly handle invalid session file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pick-to: 6.5 Change-Id: Iabb2621364b5256ac89ec8cb7fafb0a9d346515d Reviewed-by: Antti Määttä Reviewed-by: Janne Koskinen --- src/plugins/tracing/qctflib.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/plugins/tracing/qctflib.cpp b/src/plugins/tracing/qctflib.cpp index 99c40642699..3690bb63702 100644 --- a/src/plugins/tracing/qctflib.cpp +++ b/src/plugins/tracing/qctflib.cpp @@ -87,17 +87,24 @@ QCtfLibImpl::QCtfLibImpl() fclose(file); if (size != filesize) return; + QJsonDocument json(QJsonDocument::fromJson(data)); - QJsonObject obj = json.object(); - QJsonValue value = *obj.begin(); - if (value.isNull() || !value.isArray()) - return; - m_session.name = obj.begin().key(); - const QJsonArray arr = value.toArray(); - for (auto var : arr) - m_session.tracepoints.append(var.toString()); - + bool valid = false; + if (!obj.isEmpty()) { + const auto it = obj.begin(); + if (it.value().isArray()) { + m_session.name = it.key(); + for (auto var : it.value().toArray()) + m_session.tracepoints.append(var.toString()); + valid = true; + } + } + if (!valid) { + qCWarning(lcDebugTrace) << "Session file is not valid"; + m_session.tracepoints.append(QStringLiteral("all")); + m_session.name = QStringLiteral("default"); + } m_location = location + QStringLiteral("/ust"); std::filesystem::create_directory(qPrintable(m_location), qPrintable(location)); }