mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-01-26 06:26:11 -05:00
Raise error if we don't find exactly one root group.
This commit is contained in:
parent
f1bebe904a
commit
0ec29b2354
@ -151,21 +151,30 @@ bool KeePass2XmlReader::parseKeePassFile()
|
||||
{
|
||||
Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "KeePassFile");
|
||||
|
||||
bool rootParsed = false;
|
||||
bool rootElementFound = false;
|
||||
bool rootParsedSuccesfully = false;
|
||||
|
||||
while (!m_xml.error() && m_xml.readNextStartElement()) {
|
||||
if (m_xml.name() == "Meta") {
|
||||
parseMeta();
|
||||
}
|
||||
else if (m_xml.name() == "Root") {
|
||||
rootParsed = parseRoot();
|
||||
rootParsedSuccesfully = parseRoot();
|
||||
|
||||
if (rootElementFound) {
|
||||
rootParsedSuccesfully = false;
|
||||
raiseError(29);
|
||||
}
|
||||
else {
|
||||
rootElementFound = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
skipCurrentElement();
|
||||
}
|
||||
}
|
||||
|
||||
return rootParsed;
|
||||
return rootParsedSuccesfully;
|
||||
}
|
||||
|
||||
void KeePass2XmlReader::parseMeta()
|
||||
@ -423,7 +432,8 @@ bool KeePass2XmlReader::parseRoot()
|
||||
{
|
||||
Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "Root");
|
||||
|
||||
bool groupParsed = false;
|
||||
bool groupElementFound = false;
|
||||
bool groupParsedSuccesfully = false;
|
||||
|
||||
while (!m_xml.error() && m_xml.readNextStartElement()) {
|
||||
if (m_xml.name() == "Group") {
|
||||
@ -432,7 +442,15 @@ bool KeePass2XmlReader::parseRoot()
|
||||
Group* oldRoot = m_db->rootGroup();
|
||||
m_db->setRootGroup(rootGroup);
|
||||
delete oldRoot;
|
||||
groupParsed = true;
|
||||
groupParsedSuccesfully = true;
|
||||
}
|
||||
|
||||
if (groupElementFound) {
|
||||
groupParsedSuccesfully = false;
|
||||
raiseError(30);
|
||||
}
|
||||
else {
|
||||
groupElementFound = true;
|
||||
}
|
||||
}
|
||||
else if (m_xml.name() == "DeletedObjects") {
|
||||
@ -443,7 +461,7 @@ bool KeePass2XmlReader::parseRoot()
|
||||
}
|
||||
}
|
||||
|
||||
return groupParsed;
|
||||
return groupParsedSuccesfully;
|
||||
}
|
||||
|
||||
Group* KeePass2XmlReader::parseGroup()
|
||||
|
@ -370,6 +370,8 @@ void TestKeePass2XmlReader::testBroken_data()
|
||||
QTest::newRow("BrokenNoGroupUuid") << "BrokenNoGroupUuid";
|
||||
QTest::newRow("BrokenNoEntryUuid") << "BrokenNoEntryUuid";
|
||||
QTest::newRow("BrokenNoRootGroup") << "BrokenNoRootGroup";
|
||||
QTest::newRow("BrokenTwoRoots") << "BrokenTwoRoots";
|
||||
QTest::newRow("BrokenTwoRootGroups") << "BrokenTwoRootGroups";
|
||||
}
|
||||
|
||||
void TestKeePass2XmlReader::cleanupTestCase()
|
||||
|
13
tests/data/BrokenTwoRootGroups.xml
Normal file
13
tests/data/BrokenTwoRootGroups.xml
Normal file
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
|
||||
<KeePassFile>
|
||||
<Root>
|
||||
<Group>
|
||||
<UUID>lmU+9n0aeESKZvcEze+bRg==</UUID>
|
||||
<Name>Test</Name>
|
||||
</Group>
|
||||
<Group>
|
||||
<UUID>AaUYVdXsI02h4T1RiAlgtg==</UUID>
|
||||
<Name>Test</Name>
|
||||
</Group>
|
||||
</Root>
|
||||
</KeePassFile>
|
15
tests/data/BrokenTwoRoots.xml
Normal file
15
tests/data/BrokenTwoRoots.xml
Normal file
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
|
||||
<KeePassFile>
|
||||
<Root>
|
||||
<Group>
|
||||
<UUID>lmU+9n0aeESKZvcEze+bRg==</UUID>
|
||||
<Name>Test</Name>
|
||||
</Group>
|
||||
</Root>
|
||||
<Root>
|
||||
<Group>
|
||||
<UUID>AaUYVdXsI02h4T1RiAlgtg==</UUID>
|
||||
<Name>Test</Name>
|
||||
</Group>
|
||||
</Root>
|
||||
</KeePassFile>
|
Loading…
x
Reference in New Issue
Block a user