From 4d8a515a230ca9864a94830fd376a1d3ecbe6886 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Wed, 15 Jan 2020 20:53:21 +0100 Subject: QXmlStreamReader: early return in case of malformed attributes There's no point at keep raising errors after encountering the first malformed attribute. Change-Id: Idb37e577ea96c3bd850b3caf008fe3ecd57dd32e Reviewed-by: Thiago Macieira --- src/corelib/serialization/qxmlstream.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/serialization/qxmlstream.cpp b/src/corelib/serialization/qxmlstream.cpp index 500e0aa6be..dfa36ea642 100644 --- a/src/corelib/serialization/qxmlstream.cpp +++ b/src/corelib/serialization/qxmlstream.cpp @@ -50,6 +50,7 @@ #endif #include #include +#include #ifndef QT_BOOTSTRAPPED #include #else @@ -1582,6 +1583,7 @@ QStringRef QXmlStreamReaderPrivate::namespaceForPrefix(const QStringRef &prefix) */ void QXmlStreamReaderPrivate::resolveTag() { + const auto attributeStackCleaner = qScopeGuard([this](){ attributeStack.clear(); }); int n = attributeStack.size(); if (namespaceProcessing) { @@ -1649,7 +1651,10 @@ void QXmlStreamReaderPrivate::resolveTag() if (attributes[j].name() == attribute.name() && attributes[j].namespaceUri() == attribute.namespaceUri() && (namespaceProcessing || attributes[j].qualifiedName() == attribute.qualifiedName())) + { raiseWellFormedError(QXmlStream::tr("Attribute '%1' redefined.").arg(attribute.qualifiedName())); + return; + } } } @@ -1680,8 +1685,6 @@ void QXmlStreamReaderPrivate::resolveTag() attribute.m_isDefault = true; attributes.append(attribute); } - - attributeStack.clear(); } void QXmlStreamReaderPrivate::resolvePublicNamespaces() -- cgit v1.2.3