From fe877486fff8e138a96b846776a4512fabd66a0a Mon Sep 17 00:00:00 2001 From: louib Date: Sat, 29 Jul 2017 17:24:24 -0400 Subject: [PATCH] Handle FileKey::load errors (--key-file) (#825) --- src/core/Database.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/core/Database.cpp b/src/core/Database.cpp index fdfc11cfe..2e9112c7c 100644 --- a/src/core/Database.cpp +++ b/src/core/Database.cpp @@ -402,24 +402,28 @@ Database* Database::openDatabaseFile(QString fileName, CompositeKey key) Database* Database::unlockFromStdin(QString databaseFilename, QString keyFilename) { + CompositeKey compositeKey; + + if (!keyFilename.isEmpty()) { + FileKey fileKey; + QString errorMessage; + if (!fileKey.load(keyFilename, &errorMessage)) { + qCritical("Failed to load key file %s : %s", qPrintable(keyFilename), qPrintable(errorMessage)); + return nullptr; + } + compositeKey.addKey(fileKey); + } + QTextStream outputTextStream(stdout); outputTextStream << QString("Insert password to unlock " + databaseFilename + "\n> "); outputTextStream.flush(); - CompositeKey compositeKey; - QString line = Utils::getPassword(); PasswordKey passwordKey; passwordKey.setPassword(line); compositeKey.addKey(passwordKey); - if (!keyFilename.isEmpty()) { - FileKey fileKey; - fileKey.load(keyFilename); - compositeKey.addKey(fileKey); - } - return Database::openDatabaseFile(databaseFilename, compositeKey); }