Raise error if we don't find exactly one root group.

This commit is contained in:
Felix Geyer 2013-04-20 19:17:09 +02:00
parent f1bebe904a
commit 0ec29b2354
4 changed files with 54 additions and 6 deletions

View File

@ -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()

View File

@ -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()

View 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>

View 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>