Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeePass2Reader: fix error message logic #2523

Merged
merged 1 commit into from
Dec 2, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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