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; delete entry;
} }
else { else {
quint32 groupId = m_entryGroupIds.value(entry);
if (!m_groupIds.contains(groupId)) {
return 0;
}
entry->setGroup(m_groupIds.value(groupId));
entry->setUuid(Uuid::random()); entry->setUuid(Uuid::random());
} }
} }
@ -540,7 +545,7 @@ Entry* KeePass1Reader::readEntry(QIODevice* cipherStream)
return 0; return 0;
} }
quint32 groupId = Endian::bytesToUInt32(fieldData, KeePass1::BYTEORDER); quint32 groupId = Endian::bytesToUInt32(fieldData, KeePass1::BYTEORDER);
entry->setGroup(m_groupIds.value(groupId)); m_entryGroupIds.insert(entry.data(), groupId);
break; break;
} }
case 0x0003: case 0x0003:

View file

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

View file

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