summaryrefslogtreecommitdiffstats
path: root/tests/auto/xml/sax/qxmlsimplereader/tst_qxmlsimplereader.cpp
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@digia.com>2013-09-27 12:32:28 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-11-05 15:55:17 +0100
commit46a8885ae486e238a39efa5119c2714f328b08e4 (patch)
tree25301bafd9e16642b4929876a10b9727da1a674b /tests/auto/xml/sax/qxmlsimplereader/tst_qxmlsimplereader.cpp
parent55c14e35f10d5a293ae6535a1ee31963b80109a6 (diff)
Disallow deep or widely nested entity references.
Nested references with a depth of 2 or greater will fail. References that partially expand to greater than 1024 characters will also fail. Change-Id: Id4e49d6f7cf51e3a247efdb4c6c7c9bd9b223f6e Reviewed-by: Richard J. Moore <rich@kde.org> Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'tests/auto/xml/sax/qxmlsimplereader/tst_qxmlsimplereader.cpp')
-rw-r--r--tests/auto/xml/sax/qxmlsimplereader/tst_qxmlsimplereader.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/auto/xml/sax/qxmlsimplereader/tst_qxmlsimplereader.cpp b/tests/auto/xml/sax/qxmlsimplereader/tst_qxmlsimplereader.cpp
index f09fbff6c4..57d078ba65 100644
--- a/tests/auto/xml/sax/qxmlsimplereader/tst_qxmlsimplereader.cpp
+++ b/tests/auto/xml/sax/qxmlsimplereader/tst_qxmlsimplereader.cpp
@@ -160,6 +160,7 @@ class tst_QXmlSimpleReader : public QObject
void reportNamespace() const;
void reportNamespace_data() const;
void roundtripWithNamespaces() const;
+ void dtdRecursionLimit();
private:
static QDomDocument fromByteArray(const QString &title, const QByteArray &ba, bool *ok);
@@ -755,5 +756,62 @@ void tst_QXmlSimpleReader::roundtripWithNamespaces() const
}
}
+class TestHandler : public QXmlDefaultHandler
+{
+public:
+ TestHandler() :
+ recursionCount(0)
+ {
+ }
+
+ bool internalEntityDecl(const QString &name, const QString &value)
+ {
+ ++recursionCount;
+ return QXmlDefaultHandler::internalEntityDecl(name, value);
+ }
+
+ int recursionCount;
+};
+
+void tst_QXmlSimpleReader::dtdRecursionLimit()
+{
+ QFile file("xmldocs/2-levels-nested-dtd.xml");
+ QVERIFY(file.open(QIODevice::ReadOnly));
+ QXmlSimpleReader xmlReader;
+ {
+ QXmlInputSource *source = new QXmlInputSource(&file);
+ TestHandler handler;
+ xmlReader.setDeclHandler(&handler);
+ xmlReader.setErrorHandler(&handler);
+ QVERIFY(!xmlReader.parse(source));
+ }
+
+ file.close();
+ file.setFileName("xmldocs/1-levels-nested-dtd.xml");
+ QVERIFY(file.open(QIODevice::ReadOnly));
+ {
+ QXmlInputSource *source = new QXmlInputSource(&file);
+ TestHandler handler;
+ xmlReader.setDeclHandler(&handler);
+ xmlReader.setErrorHandler(&handler);
+ QVERIFY(!xmlReader.parse(source));
+ // The error wasn't because of the recursion limit being reached,
+ // it was because the document is not valid.
+ QVERIFY(handler.recursionCount < 2);
+ }
+
+ file.close();
+ file.setFileName("xmldocs/internal-entity-polynomial-attribute.xml");
+ QVERIFY(file.open(QIODevice::ReadOnly));
+ {
+ QXmlInputSource *source = new QXmlInputSource(&file);
+ TestHandler handler;
+ xmlReader.setDeclHandler(&handler);
+ xmlReader.setErrorHandler(&handler);
+ QVERIFY(!xmlReader.parse(source));
+ QVERIFY(handler.recursionCount == 1);
+ }
+}
+
QTEST_MAIN(tst_QXmlSimpleReader)
#include "tst_qxmlsimplereader.moc"