Make KeePass2XmlReader::parseGroup() safe against reordered xml elements.

This commit is contained in:
Felix Geyer 2013-04-14 14:54:56 +02:00
parent 3acb33e05a
commit 5588792344
3 changed files with 28 additions and 4 deletions

View File

@ -490,6 +490,12 @@ Group* Group::clone() const
return clonedGroup;
}
void Group::copyDataFrom(const Group* other)
{
m_data = other->m_data;
m_lastTopVisibleEntry = other->m_lastTopVisibleEntry;
}
void Group::addEntry(Entry* entry)
{
Q_ASSERT(entry);

View File

@ -101,6 +101,7 @@ public:
QList<const Group*> groupsRecursive(bool includeSelf) const;
QSet<Uuid> customIconsRecursive() const;
Group* clone() const;
void copyDataFrom(const Group* other);
QList<Entry*> search(const QString& searchTerm, Qt::CaseSensitivity caseSensitivity,
bool resolveInherit = true);

View File

@ -411,7 +411,10 @@ Group* KeePass2XmlReader::parseGroup()
{
Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "Group");
Group* group = Q_NULLPTR;
Group* group = new Group();
group->setUpdateTimeinfo(false);
QList<Group*> children;
QList<Entry*> entries;
while (!m_xml.error() && m_xml.readNextStartElement()) {
if (m_xml.name() == "UUID") {
Uuid uuid = readUuid();
@ -419,7 +422,7 @@ Group* KeePass2XmlReader::parseGroup()
raiseError(1);
}
else {
group = getGroup(uuid);
group->setUuid(uuid);
}
}
else if (m_xml.name() == "Name") {
@ -493,13 +496,13 @@ Group* KeePass2XmlReader::parseGroup()
else if (m_xml.name() == "Group") {
Group* newGroup = parseGroup();
if (newGroup) {
newGroup->setParent(group);
children.append(newGroup);
}
}
else if (m_xml.name() == "Entry") {
Entry* newEntry = parseEntry(false);
if (newEntry) {
newEntry->setGroup(group);
entries.append(newEntry);
}
}
else {
@ -507,6 +510,20 @@ Group* KeePass2XmlReader::parseGroup()
}
}
Group* tmpGroup = group;
group = getGroup(tmpGroup->uuid());
group->copyDataFrom(tmpGroup);
group->setUpdateTimeinfo(false);
delete tmpGroup;
Q_FOREACH (Group* child, children) {
child->setParent(group);
}
Q_FOREACH (Entry* entry, entries) {
entry->setGroup(group);
}
return group;
}