1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-12-22 10:37:59 +01:00

Fix possible NPE in roster push listener

Daniele Ricci reporting the following NPE using Smack 4.1.9

java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.indexOf(int)' on a null object reference
       at org.jxmpp.util.XmppStringUtils.parseBareJid(XmppStringUtils.java:124)
       at org.jivesoftware.smack.roster.Roster$RosterPushListener.handleIQRequest(Roster.java:1416)
       at org.jivesoftware.smack.AbstractXMPPConnection$2.run(AbstractXMPPConnection.java:1061)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
       at java.lang.Thread.run(Thread.java:818)

This is possibly caused by a service sending roster pushes for unbound
connections, i.e. where getUsers() returns 'null'. We now log such
situations instead throwing an NPE.
This commit is contained in:
Florian Schmaus 2017-03-07 08:50:22 +01:00
parent 6b7a8142c9
commit e141de9aa4

View file

@ -66,6 +66,7 @@ import org.jivesoftware.smack.roster.rosterstore.RosterStore;
import org.jivesoftware.smack.util.Objects;
import org.jxmpp.jid.BareJid;
import org.jxmpp.jid.EntityBareJid;
import org.jxmpp.jid.EntityFullJid;
import org.jxmpp.jid.Jid;
import org.jxmpp.jid.FullJid;
import org.jxmpp.jid.impl.JidCreate;
@ -1674,9 +1675,16 @@ public final class Roster extends Manager {
final XMPPConnection connection = connection();
RosterPacket rosterPacket = (RosterPacket) iqRequest;
EntityFullJid localAddress = connection.getUser();
if (localAddress == null) {
LOGGER.warning("Ignoring roster push " + iqRequest + " while " + connection
+ " has no bound resource. This may be a server bug.");
return null;
}
// Roster push (RFC 6121, 2.1.6)
// A roster push with a non-empty from not matching our address MUST be ignored
EntityBareJid jid = connection.getUser().asEntityBareJid();
EntityBareJid jid = localAddress.asEntityBareJid();
Jid from = rosterPacket.getFrom();
if (from != null && !from.equals(jid)) {
LOGGER.warning("Ignoring roster push with a non matching 'from' ourJid='" + jid + "' from='" + from