mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-08-21 12:38:12 -04:00
Make KeePass2XmlReader::parseGroup() safe against reordered xml elements.
This commit is contained in:
parent
3acb33e05a
commit
5588792344
3 changed files with 28 additions and 4 deletions
|
@ -490,6 +490,12 @@ Group* Group::clone() const
|
||||||
return clonedGroup;
|
return clonedGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Group::copyDataFrom(const Group* other)
|
||||||
|
{
|
||||||
|
m_data = other->m_data;
|
||||||
|
m_lastTopVisibleEntry = other->m_lastTopVisibleEntry;
|
||||||
|
}
|
||||||
|
|
||||||
void Group::addEntry(Entry* entry)
|
void Group::addEntry(Entry* entry)
|
||||||
{
|
{
|
||||||
Q_ASSERT(entry);
|
Q_ASSERT(entry);
|
||||||
|
|
|
@ -101,6 +101,7 @@ public:
|
||||||
QList<const Group*> groupsRecursive(bool includeSelf) const;
|
QList<const Group*> groupsRecursive(bool includeSelf) const;
|
||||||
QSet<Uuid> customIconsRecursive() const;
|
QSet<Uuid> customIconsRecursive() const;
|
||||||
Group* clone() const;
|
Group* clone() const;
|
||||||
|
void copyDataFrom(const Group* other);
|
||||||
|
|
||||||
QList<Entry*> search(const QString& searchTerm, Qt::CaseSensitivity caseSensitivity,
|
QList<Entry*> search(const QString& searchTerm, Qt::CaseSensitivity caseSensitivity,
|
||||||
bool resolveInherit = true);
|
bool resolveInherit = true);
|
||||||
|
|
|
@ -411,7 +411,10 @@ Group* KeePass2XmlReader::parseGroup()
|
||||||
{
|
{
|
||||||
Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "Group");
|
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()) {
|
while (!m_xml.error() && m_xml.readNextStartElement()) {
|
||||||
if (m_xml.name() == "UUID") {
|
if (m_xml.name() == "UUID") {
|
||||||
Uuid uuid = readUuid();
|
Uuid uuid = readUuid();
|
||||||
|
@ -419,7 +422,7 @@ Group* KeePass2XmlReader::parseGroup()
|
||||||
raiseError(1);
|
raiseError(1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
group = getGroup(uuid);
|
group->setUuid(uuid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (m_xml.name() == "Name") {
|
else if (m_xml.name() == "Name") {
|
||||||
|
@ -493,13 +496,13 @@ Group* KeePass2XmlReader::parseGroup()
|
||||||
else if (m_xml.name() == "Group") {
|
else if (m_xml.name() == "Group") {
|
||||||
Group* newGroup = parseGroup();
|
Group* newGroup = parseGroup();
|
||||||
if (newGroup) {
|
if (newGroup) {
|
||||||
newGroup->setParent(group);
|
children.append(newGroup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (m_xml.name() == "Entry") {
|
else if (m_xml.name() == "Entry") {
|
||||||
Entry* newEntry = parseEntry(false);
|
Entry* newEntry = parseEntry(false);
|
||||||
if (newEntry) {
|
if (newEntry) {
|
||||||
newEntry->setGroup(group);
|
entries.append(newEntry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
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;
|
return group;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue