From 94430c300bfda8bbb99ff67ad722a746336a9a78 Mon Sep 17 00:00:00 2001 From: Carlo Teubner <435950+c4rlo@users.noreply.github.com> Date: Mon, 21 Jan 2019 19:24:29 +0000 Subject: [PATCH] CLI: fix missing check for correct credentials (#2629) * CLI: fix missing check for correct credentials Before this fix, most/all CLI commands had incorrect behaviour when bad credentials were supplied: they would carry on regardless, with potentially catastrophic results. In particular, the "add" subcommand seemed to corrupt the database. "ls" would always report an empty database. Haven't tested any others. Also fixed a related missing check specific to the "merge" subcommand. --- src/cli/Merge.cpp | 3 +++ src/cli/Utils.cpp | 9 +++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/cli/Merge.cpp b/src/cli/Merge.cpp index 39dcf21f..5bd926eb 100644 --- a/src/cli/Merge.cpp +++ b/src/cli/Merge.cpp @@ -79,6 +79,9 @@ int Merge::execute(const QStringList& arguments) QSharedPointer db2; if (!parser.isSet("same-credentials")) { db2 = Utils::unlockDatabase(args.at(1), parser.value(keyFileFromOption), Utils::STDOUT, Utils::STDERR); + if (!db2) { + return EXIT_FAILURE; + } } else { db2 = QSharedPointer::create(); QString errorMessage; diff --git a/src/cli/Utils.cpp b/src/cli/Utils.cpp index 26434669..a1513a7f 100644 --- a/src/cli/Utils.cpp +++ b/src/cli/Utils.cpp @@ -135,8 +135,13 @@ QSharedPointer unlockDatabase(const QString& databaseFilename, } auto db = QSharedPointer::create(); - db->open(databaseFilename, compositeKey, nullptr, false); - return db; + QString error; + if (db->open(databaseFilename, compositeKey, &error, false)) { + return db; + } else { + err << error << endl; + return {}; + } } /**