mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-12-27 16:29:44 -05:00
Make KeePass2XmlReader::parseGroup() safe against reordered xml elements.
This commit is contained in:
parent
3acb33e05a
commit
5588792344
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user