From 31e4e1faf20be0fc889ea62a8737518f4ecb5aac Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Tue, 6 Jul 2021 12:33:11 +0200 Subject: [PATCH] Do not call XmlPullParser.getName() when the event is unknown XmlPullParser.getName() only returns a result if the current parser event is START_ELEMENT or END_ELEMENT. If this is not the case, then the method may throw (if StAX is used). --- .../provider/IoTSetRequestProvider.java | 4 ++-- .../provider/IoTFieldsExtensionProvider.java | 2 +- .../mam/provider/MamPrefsIQProvider.java | 4 ++-- .../mam/provider/MamQueryIQProvider.java | 2 +- .../mam/provider/MamResultProvider.java | 2 +- .../provider/MarkupElementProvider.java | 11 +++++---- .../provider/AdHocCommandDataProvider.java | 2 +- .../provider/JingleS5BTransportProvider.java | 6 ++--- .../smackx/mood/provider/MoodProvider.java | 6 ++--- .../si/provider/StreamInitiationProvider.java | 17 ++++++-------- .../provider/XHTMLExtensionProvider.java | 4 ++-- .../smackx/jingleold/nat/RTPBridge.java | 3 +-- .../JingleContentDescriptionProvider.java | 9 ++++---- .../provider/JingleDescriptionProvider.java | 10 ++++---- .../jingleold/provider/JingleProvider.java | 4 ++-- .../provider/JingleTransportProvider.java | 9 ++++---- .../workgroup/agent/OfferConfirmation.java | 19 ++++----------- .../smackx/workgroup/packet/QueueUpdate.java | 23 ++++++++----------- .../workgroup/packet/RoomInvitation.java | 9 ++++---- .../smackx/workgroup/packet/RoomTransfer.java | 9 ++++---- .../provider/OmemoBundleVAxolotlProvider.java | 10 ++++---- .../OmemoDeviceListVAxolotlProvider.java | 12 ++++------ .../omemo/provider/OmemoVAxolotlProvider.java | 10 ++++---- .../ox/provider/PubkeyElementProvider.java | 2 +- 24 files changed, 80 insertions(+), 109 deletions(-) diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/iot/control/provider/IoTSetRequestProvider.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/iot/control/provider/IoTSetRequestProvider.java index 029e1f15e..952ebcdd8 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/iot/control/provider/IoTSetRequestProvider.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/iot/control/provider/IoTSetRequestProvider.java @@ -1,6 +1,6 @@ /** * - * Copyright © 2016-2019 Florian Schmaus + * Copyright © 2016-2021 Florian Schmaus * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,9 +39,9 @@ public class IoTSetRequestProvider extends IQProvider { List data = new ArrayList<>(4); outerloop: while (true) { final XmlPullParser.Event eventType = parser.next(); - final String name = parser.getName(); switch (eventType) { case START_ELEMENT: + final String name = parser.getName(); switch (name) { case "bool": { String valueName = parser.getAttributeValue(null, "name"); diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/iot/data/provider/IoTFieldsExtensionProvider.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/iot/data/provider/IoTFieldsExtensionProvider.java index fbe9b2d7f..5dfeaa5ba 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/iot/data/provider/IoTFieldsExtensionProvider.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/iot/data/provider/IoTFieldsExtensionProvider.java @@ -115,9 +115,9 @@ public class IoTFieldsExtensionProvider extends ExtensionElementProvider fields = new ArrayList<>(); outerloop: while (true) { final XmlPullParser.Event eventType = parser.next(); - final String name = parser.getName(); switch (eventType) { case START_ELEMENT: + final String name = parser.getName(); IoTDataField field = null; final String fieldName = parser.getAttributeValue(null, "name"); final String fieldValue = parser.getAttributeValue(null, "value"); diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/provider/MamPrefsIQProvider.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/provider/MamPrefsIQProvider.java index 632ae4946..2b4795036 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/provider/MamPrefsIQProvider.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/provider/MamPrefsIQProvider.java @@ -59,9 +59,9 @@ public class MamPrefsIQProvider extends IQProvider { outerloop: while (true) { final XmlPullParser.Event eventType = parser.next(); - final String name = parser.getName(); switch (eventType) { case START_ELEMENT: + final String name = parser.getName(); switch (name) { case "always": alwaysJids = iterateJids(parser); @@ -92,9 +92,9 @@ public class MamPrefsIQProvider extends IQProvider { outerloop: while (true) { final XmlPullParser.Event eventType = parser.next(); - final String name = parser.getName(); switch (eventType) { case START_ELEMENT: + final String name = parser.getName(); switch (name) { case "jid": parser.next(); diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/provider/MamQueryIQProvider.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/provider/MamQueryIQProvider.java index 853f199f4..d0971c5de 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/provider/MamQueryIQProvider.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/provider/MamQueryIQProvider.java @@ -47,10 +47,10 @@ public class MamQueryIQProvider extends IQProvider { outerloop: while (true) { final XmlPullParser.Event eventType = parser.next(); - final String name = parser.getName(); switch (eventType) { case START_ELEMENT: + final String name = parser.getName(); switch (name) { case DataForm.ELEMENT: dataForm = DataFormProvider.INSTANCE.parse(parser); diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/provider/MamResultProvider.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/provider/MamResultProvider.java index 7999a0e13..f0d465ffb 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/provider/MamResultProvider.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/provider/MamResultProvider.java @@ -47,9 +47,9 @@ public class MamResultProvider extends ExtensionElementProvider { } while (!done) { eventType = parser.next(); - elementName = parser.getName(); namespace = parser.getNamespace(); if (eventType == XmlPullParser.Event.START_ELEMENT) { + elementName = parser.getName(); if (parser.getName().equals("actions")) { String execute = parser.getAttributeValue("", "execute"); if (execute != null) { diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transports/jingle_s5b/provider/JingleS5BTransportProvider.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transports/jingle_s5b/provider/JingleS5BTransportProvider.java index 7f85961db..c88651661 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transports/jingle_s5b/provider/JingleS5BTransportProvider.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transports/jingle_s5b/provider/JingleS5BTransportProvider.java @@ -31,7 +31,6 @@ import org.jivesoftware.smack.packet.XmlEnvironment; import org.jivesoftware.smack.xml.XmlPullParser; import org.jivesoftware.smack.xml.XmlPullParserException; -import org.jivesoftware.smackx.jingle.element.JingleContentTransport; import org.jivesoftware.smackx.jingle.element.JingleContentTransportCandidate; import org.jivesoftware.smackx.jingle.provider.JingleContentTransportProvider; import org.jivesoftware.smackx.jingle.transports.jingle_s5b.elements.JingleS5BTransport; @@ -62,9 +61,9 @@ public class JingleS5BTransportProvider extends JingleContentTransportProvider { outerloop: while (true) { XmlPullParser.Event tag = parser.next(); - String name = parser.getName(); - String namespace = parser.getNamespace(); switch (tag) { case START_ELEMENT: + String name = parser.getName(); + String namespace = parser.getNamespace(); if (MoodElement.ELEM_TEXT.equals(name)) { text = parser.nextText(); continue outerloop; @@ -74,7 +74,7 @@ public class MoodProvider extends ExtensionElementProvider { } case END_ELEMENT: - if (MoodElement.ELEMENT.equals(name)) { + if (MoodElement.ELEMENT.equals(parser.getName())) { MoodElement.MoodSubjectElement subjectElement = (mood == null && concretisation == null) ? null : new MoodElement.MoodSubjectElement(mood, concretisation); return new MoodElement(subjectElement, text); diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/si/provider/StreamInitiationProvider.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/si/provider/StreamInitiationProvider.java index f1719682c..6da4cafc9 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/si/provider/StreamInitiationProvider.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/si/provider/StreamInitiationProvider.java @@ -46,8 +46,6 @@ public class StreamInitiationProvider extends IQProvider { @Override public StreamInitiation parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException { - boolean done = false; - // si String id = parser.getAttributeValue("", "id"); String mimeType = parser.getAttributeValue("", "mime-type"); @@ -66,13 +64,11 @@ public class StreamInitiationProvider extends IQProvider { DataForm form = null; DataFormProvider dataFormProvider = new DataFormProvider(); - String elementName; - String namespace; - while (!done) { + outerloop: while (true) { XmlPullParser.Event eventType = parser.next(); - elementName = parser.getName(); - namespace = parser.getNamespace(); if (eventType == XmlPullParser.Event.START_ELEMENT) { + String elementName = parser.getName(); + String namespace = parser.getNamespace(); if (elementName.equals("file")) { name = parser.getAttributeValue("", "name"); size = parser.getAttributeValue("", "size"); @@ -87,9 +83,10 @@ public class StreamInitiationProvider extends IQProvider { form = dataFormProvider.parse(parser); } } else if (eventType == XmlPullParser.Event.END_ELEMENT) { - if (elementName.equals("si")) { - done = true; - } else if (elementName.equals("file")) { + if (parser.getDepth() == initialDepth) { + break outerloop; + } + if (parser.getName().equals("file")) { long fileSize = 0; if (size != null && size.trim().length() != 0) { try { diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/xhtmlim/provider/XHTMLExtensionProvider.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/xhtmlim/provider/XHTMLExtensionProvider.java index 71f15fe53..a09741400 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/xhtmlim/provider/XHTMLExtensionProvider.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/xhtmlim/provider/XHTMLExtensionProvider.java @@ -1,6 +1,6 @@ /** * - * Copyright 2003-2007 Jive Software, 2014-2019 Florian Schmaus + * Copyright 2003-2007 Jive Software, 2014-2021 Florian Schmaus * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,8 +40,8 @@ public class XHTMLExtensionProvider extends ExtensionElementProvider { // Start processing sub-elements while (!done) { eventType = parser.next(); - elementName = parser.getName(); - namespace = parser.getNamespace(); if (eventType == XmlPullParser.Event.START_ELEMENT) { + elementName = parser.getName(); + namespace = parser.getNamespace(); // Parse some well know subelements, depending on the namespaces // and element names... diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/provider/JingleTransportProvider.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/provider/JingleTransportProvider.java index 12d98e8a1..7462de72e 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/provider/JingleTransportProvider.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/provider/JingleTransportProvider.java @@ -54,14 +54,13 @@ public abstract class JingleTransportProvider extends ExtensionElementProvider { @Override public OmemoBundleElement_VAxolotl parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException { - boolean stop = false; boolean inPreKeys = false; int signedPreKeyId = -1; @@ -52,11 +50,11 @@ public class OmemoBundleVAxolotlProvider extends ExtensionElementProvider preKeys = new HashMap<>(); - while (!stop) { + outerloop: while (true) { XmlPullParser.Event tag = parser.next(); - String name = parser.getName(); switch (tag) { case START_ELEMENT: + String name = parser.getName(); final int attributeCount = parser.getAttributeCount(); // if (name.equals(SIGNED_PRE_KEY_PUB)) { @@ -91,8 +89,8 @@ public class OmemoBundleVAxolotlProvider extends ExtensionElementProvider deviceListIds = new HashSet<>(); - boolean stop = false; - while (!stop) { + outerloop: while (true) { XmlPullParser.Event tag = parser.next(); - String name = parser.getName(); switch (tag) { case START_ELEMENT: + String name = parser.getName(); if (name.equals(DEVICE)) { for (int i = 0; i < parser.getAttributeCount(); i++) { if (parser.getAttributeName(i).equals(ID)) { @@ -57,8 +55,8 @@ public class OmemoDeviceListVAxolotlProvider extends ExtensionElementProvider keys = new ArrayList<>(); byte[] iv = null; byte[] payload = null; - while (inEncrypted) { + outerloop: while (true) { XmlPullParser.Event tag = parser.next(); - String name = parser.getName(); switch (tag) { case START_ELEMENT: + String name = parser.getName(); switch (name) { case OmemoHeaderElement.ELEMENT: for (int i = 0; i < parser.getAttributeCount(); i++) { @@ -82,8 +80,8 @@ public class OmemoVAxolotlProvider extends ExtensionElementProvider