From 431f9a20c849fb438ca743d6989ad768d568e91d Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sun, 16 Jul 2017 19:53:43 +0200 Subject: Sanity check queries --- common/store.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'common') diff --git a/common/store.cpp b/common/store.cpp index 29e826a..392f9ce 100644 --- a/common/store.cpp +++ b/common/store.cpp @@ -40,6 +40,25 @@ Q_DECLARE_METATYPE(QSharedPointer); Q_DECLARE_METATYPE(std::shared_ptr); + +static bool sanityCheckQuery(const Sink::Query &query) +{ + for (const auto &id : query.ids()) { + if (id.isEmpty()) { + SinkError() << "Empty id in query."; + return false; + } + } + for (const auto &id : query.getResourceFilter().ids) { + if (id.isEmpty()) { + SinkError() << "Empty resourceid in query."; + return false; + } + } + return true; +} + + namespace Sink { QString Store::storageLocation() @@ -138,6 +157,7 @@ static Log::Context getQueryContext(const Sink::Query &query, const QByteArray & template QSharedPointer Store::loadModel(const Query &query) { + Q_ASSERT(sanityCheckQuery(query)); auto ctx = getQueryContext(query, ApplicationDomain::getTypeName()); auto model = QSharedPointer>::create(query, query.requestedProperties, ctx); @@ -342,6 +362,7 @@ KAsync::Job> Store::fetchAll(const Sink::Query & template KAsync::Job> Store::fetch(const Sink::Query &query, int minimumAmount) { + Q_ASSERT(sanityCheckQuery(query)); auto model = loadModel(query); auto list = QSharedPointer>::create(); auto context = QSharedPointer::create(); @@ -393,6 +414,7 @@ DomainType Store::readOne(const Sink::Query &query) template QList Store::read(const Sink::Query &query_) { + Q_ASSERT(sanityCheckQuery(query_)); auto query = query_; query.setFlags(Query::SynchronousQuery); -- cgit v1.2.3