Skip to content

Commit

Permalink
KeePass2Reader: fix error message logic (#2523)
Browse files Browse the repository at this point in the history
  • Loading branch information
c4rlo authored and droidmonkey committed Dec 2, 2018
1 parent bdee748 commit b6eeaba
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/format/KeePass2Reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,25 @@ bool KeePass2Reader::readDatabase(QIODevice* device, QSharedPointer<const Compos
quint32 signature1, signature2;
bool ok = KdbxReader::readMagicNumbers(device, signature1, signature2, m_version);

// mask out minor version
m_version &= KeePass2::FILE_VERSION_CRITICAL_MASK;

if (!ok || signature1 != KeePass2::SIGNATURE_1 || signature2 != KeePass2::SIGNATURE_2) {
raiseError(tr("Not a KeePass database."));
if (!ok) {
raiseError(tr("Failed to read database file."));
return false;
}

if (signature2 == KeePass1::SIGNATURE_2) {
if (signature1 == KeePass1::SIGNATURE_1 && signature2 == KeePass1::SIGNATURE_2) {
raiseError(tr("The selected file is an old KeePass 1 database (.kdb).\n\n"
"You can import it by clicking on Database > 'Import KeePass 1 database...'.\n"
"This is a one-way migration. You won't be able to open the imported "
"database with the old KeePassX 0.4 version."));
return false;
} else if (!(signature1 == KeePass2::SIGNATURE_1 && signature2 == KeePass2::SIGNATURE_2)) {
raiseError(tr("Not a KeePass database."));
return false;
}

// mask out minor version
m_version &= KeePass2::FILE_VERSION_CRITICAL_MASK;

quint32 maxVersion = KeePass2::FILE_VERSION_4 & KeePass2::FILE_VERSION_CRITICAL_MASK;
if (m_version < KeePass2::FILE_VERSION_MIN || m_version > maxVersion) {
raiseError(tr("Unsupported KeePass 2 database version."));
Expand Down

0 comments on commit b6eeaba

Please sign in to comment.