mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-22 12:02:05 +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:
parent
5dd08fc215
commit
02d8f53246
2 changed files with 21 additions and 2 deletions
|
@ -1460,7 +1460,14 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
||||||
int parserDepth = parser.getDepth();
|
int parserDepth = parser.getDepth();
|
||||||
Stanza stanza = null;
|
Stanza stanza = null;
|
||||||
try {
|
try {
|
||||||
stanza = PacketParserUtils.parseStanza(parser, incomingStreamXmlEnvironment);
|
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) {
|
catch (XmlPullParserException | SmackParsingException | IOException | IllegalArgumentException e) {
|
||||||
CharSequence content = PacketParserUtils.parseContentDepth(parser,
|
CharSequence content = PacketParserUtils.parseContentDepth(parser,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Copyright 2020-2021 Florian Schmaus
|
* Copyright 2020-2024 Florian Schmaus
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -17,6 +17,8 @@
|
||||||
package org.jivesoftware.smack;
|
package org.jivesoftware.smack;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.jivesoftware.smack.util.FileUtils;
|
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 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".
|
* Returns the Smack version information, e.g."1.3.0".
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue