File Replace-several-Q_ASSERTs-with-proper-checks.patch of Package baloo5

From 75db0004ad025a5b8a533b1e3164cd36d62bc565 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20Br=C3=BCns?= <stefan.bruens@rwth-aachen.de>
Date: Fri, 8 Feb 2019 15:23:07 +0100
Subject: Replace several Q_ASSERTs with proper checks

Summary:
The code has some preconditions on supplied values when interacting
with the DB. Instead of silently corrupting the DB with bogus values
when using non-debug builds, check any provided arguments.

Reviewers: #baloo, #frameworks, ngraham, poboiko, dhaumann

Reviewed By: dhaumann

Subscribers: dhaumann, ngraham, apol, sitter, kde-frameworks-devel, broulik, #frameworks

Tags: #frameworks, #baloo

Differential Revision: https://phabricator.kde.org/D12336
---
 src/engine/documenturldb.cpp | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/src/engine/documenturldb.cpp b/src/engine/documenturldb.cpp
index 1aa5118..fb35edd 100644
--- a/src/engine/documenturldb.cpp
+++ b/src/engine/documenturldb.cpp
@@ -41,9 +41,9 @@ DocumentUrlDB::~DocumentUrlDB()
 
 bool DocumentUrlDB::put(quint64 docId, const QByteArray& url)
 {
-    Q_ASSERT(docId > 0);
-    Q_ASSERT(!url.isEmpty());
-    Q_ASSERT(!url.endsWith('/'));
+    if (!docId || url.isEmpty() || url.endsWith('/')) {
+        return false;
+    }
 
     IdFilenameDB idFilenameDb(m_idFilenameDbi, m_txn);
 
@@ -104,8 +104,9 @@ bool DocumentUrlDB::put(quint64 docId, const QByteArray& url)
 
 void DocumentUrlDB::add(quint64 id, quint64 parentId, const QByteArray& name)
 {
-    Q_ASSERT(id > 0);
-    Q_ASSERT(!name.isEmpty());
+    if (!id || name.isEmpty()) {
+        return;
+    }
 
     IdFilenameDB idFilenameDb(m_idFilenameDbi, m_txn);
     IdTreeDB idTreeDb(m_idTreeDbi, m_txn);
@@ -127,7 +128,9 @@ void DocumentUrlDB::add(quint64 id, quint64 parentId, const QByteArray& name)
 
 QByteArray DocumentUrlDB::get(quint64 docId) const
 {
-    Q_ASSERT(docId > 0);
+    if (!docId) {
+        return QByteArray();
+    }
 
     IdFilenameDB idFilenameDb(m_idFilenameDbi, m_txn);
 
@@ -166,7 +169,9 @@ QVector<quint64> DocumentUrlDB::getChildren(quint64 docId) const
 
 void DocumentUrlDB::rename(quint64 docId, const QByteArray& newFileName)
 {
-    Q_ASSERT(docId > 0);
+    if (!docId || newFileName.isEmpty()) {
+        return;
+    }
 
     IdFilenameDB idFilenameDb(m_idFilenameDbi, m_txn);
 
@@ -177,7 +182,9 @@ void DocumentUrlDB::rename(quint64 docId, const QByteArray& newFileName)
 
 quint64 DocumentUrlDB::getId(quint64 docId, const QByteArray& fileName) const
 {
-    Q_ASSERT(!fileName.isEmpty());
+    if (fileName.isEmpty()) {
+        return 0;
+    }
 
     IdFilenameDB idFilenameDb(m_idFilenameDbi, m_txn);
     IdTreeDB idTreeDb(m_idTreeDbi, m_txn);
-- 
cgit v1.1

openSUSE Build Service is sponsored by