Make sure we don't create DeletedObjects when importing databases.

This commit is contained in:
Felix Geyer 2012-05-10 22:54:26 +02:00
parent 366d8a0f0e
commit 65bdc207b7
3 changed files with 9 additions and 1 deletions

View File

@ -198,6 +198,11 @@ Database* KeePass1Reader::readDatabase(QIODevice* device, const QString& passwor
delete entry;
}
else {
quint32 groupId = m_entryGroupIds.value(entry);
if (!m_groupIds.contains(groupId)) {
return 0;
}
entry->setGroup(m_groupIds.value(groupId));
entry->setUuid(Uuid::random());
}
}
@ -540,7 +545,7 @@ Entry* KeePass1Reader::readEntry(QIODevice* cipherStream)
return 0;
}
quint32 groupId = Endian::bytesToUInt32(fieldData, KeePass1::BYTEORDER);
entry->setGroup(m_groupIds.value(groupId));
m_entryGroupIds.insert(entry.data(), groupId);
break;
}
case 0x0003:

View File

@ -76,6 +76,7 @@ private:
QHash<quint32, Group*> m_groupIds;
QHash<Group*, quint32> m_groupLevels;
QHash<QByteArray, Entry*> m_entryUuids;
QHash<Entry*, quint32> m_entryGroupIds;
bool m_error;
QString m_errorStr;

View File

@ -47,6 +47,8 @@ void TestKeePass1Reader::initTestCase()
void TestKeePass1Reader::testBasic()
{
QVERIFY(m_db->deletedObjects().isEmpty());
QCOMPARE(m_db->rootGroup()->children().size(), 2);
Group* group1 = m_db->rootGroup()->children().at(0);