1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-25 21:42:07 +01:00

[core] Increase resilience against faulty parser implementions

If one of the parser throws a NullPointerException or
NumberFormatException, then this should not lead to a disconnect due
to an unhandled exception. Instead wrap those in an exception that is
handled by the parsing exception callback and ask the user to fill a
bug report for those faulty parsers.

We may adjust the list of exceptions that are wrapped in the future.
This commit is contained in:
Florian Schmaus 2024-10-15 12:47:55 +02:00
parent 5dd08fc215
commit 02d8f53246
2 changed files with 21 additions and 2 deletions

View file

@ -1459,8 +1459,15 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
ParserUtils.assertAtStartTag(parser);
int parserDepth = parser.getDepth();
Stanza stanza = null;
try {
try {
stanza = PacketParserUtils.parseStanza(parser, incomingStreamXmlEnvironment);
} catch (NullPointerException | NumberFormatException e) {
// Those exceptions should probably be wrapped into a SmackParsingException and therefore likely constitute a missing verification in the throwing parser.
String message = "Smack parser throw unexpected exception '" + e.getMessage() + "', please report this at " + Smack.BUG_REPORT_URL;
LOGGER.log(Level.SEVERE, message, e);
throw new IOException(message, e);
}
}
catch (XmlPullParserException | SmackParsingException | IOException | IllegalArgumentException e) {
CharSequence content = PacketParserUtils.parseContentDepth(parser,

View file

@ -1,6 +1,6 @@
/**
*
* Copyright 2020-2021 Florian Schmaus
* Copyright 2020-2024 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -17,6 +17,8 @@
package org.jivesoftware.smack;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Logger;
import org.jivesoftware.smack.util.FileUtils;
@ -29,6 +31,16 @@ public class Smack {
public static final String SMACK_PACKAGE = SMACK_ORG + ".smack";
public static final URL BUG_REPORT_URL;
static {
try {
BUG_REPORT_URL = new URL("https://discourse.igniterealtime.org/c/smack/smack-support/9");
} catch (MalformedURLException e) {
throw new ExceptionInInitializerError(e);
}
}
/**
* Returns the Smack version information, e.g."1.3.0".
*