diff options
author | Christian Schneppe <christian@pix-art.de> | 2018-05-02 21:07:14 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2018-05-02 21:07:14 +0200 |
commit | f6df6c36040882ec01eb6a21ad24d15b8232875d (patch) | |
tree | d4784495a58bdefdab66f1df68da3dae14b1d2c6 /src/main/java | |
parent | 6dac604f4065429b7d9390eed01bde94844268a9 (diff) |
check if jid was valid before parsing muc status or event msgs
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/de/pixart/messenger/parser/MessageParser.java | 8 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/xmpp/InvalidJid.java | 14 |
2 files changed, 16 insertions, 6 deletions
diff --git a/src/main/java/de/pixart/messenger/parser/MessageParser.java b/src/main/java/de/pixart/messenger/parser/MessageParser.java index c72af97aa..3e6483650 100644 --- a/src/main/java/de/pixart/messenger/parser/MessageParser.java +++ b/src/main/java/de/pixart/messenger/parser/MessageParser.java @@ -407,7 +407,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece return; } boolean isProperlyAddressed = (to != null) && (!to.isBareJid() || account.countPresences() == 0); - boolean isMucStatusMessage = from.isBareJid() && mucUserElement != null && mucUserElement.hasChild("status"); + boolean isMucStatusMessage = InvalidJid.hasValidFrom(packet) && from.isBareJid() && mucUserElement != null && mucUserElement.hasChild("status"); boolean selfAddressed; if (packet.fromAccount(account)) { status = Message.STATUS_SEND; @@ -759,7 +759,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece } } } - if (conversation != null && mucUserElement != null && from.isBareJid()) { + if (conversation != null && mucUserElement != null && InvalidJid.hasValidFrom(packet) && from.isBareJid()) { for (Element child : mucUserElement.getChildren()) { if ("status".equals(child.getName())) { try { @@ -861,12 +861,12 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece } Element event = original.findChild("event", "http://jabber.org/protocol/pubsub#event"); - if (event != null) { + if (event != null && InvalidJid.hasValidFrom(original)) { parseEvent(event, original.getFrom(), account); } final String nick = packet.findChildContent("nick", Namespace.NICK); - if (nick != null) { + if (nick != null && InvalidJid.hasValidFrom(original)) { Contact contact = account.getRoster().getContact(from); if (contact.setPresenceName(nick)) { mXmppConnectionService.getAvatarService().clear(contact); diff --git a/src/main/java/de/pixart/messenger/xmpp/InvalidJid.java b/src/main/java/de/pixart/messenger/xmpp/InvalidJid.java index a22bd6cef..ce381abdc 100644 --- a/src/main/java/de/pixart/messenger/xmpp/InvalidJid.java +++ b/src/main/java/de/pixart/messenger/xmpp/InvalidJid.java @@ -31,6 +31,7 @@ package de.pixart.messenger.xmpp; import android.support.annotation.NonNull; +import de.pixart.messenger.xmpp.stanzas.AbstractStanza; import rocks.xmpp.addr.Jid; public class InvalidJid implements Jid { @@ -141,10 +142,19 @@ public class InvalidJid implements Jid { } public static boolean isValid(Jid jid) { - if (jid != null && jid instanceof InvalidJid) { + return !(jid != null && jid instanceof InvalidJid); + } + + public static boolean hasValidFrom(AbstractStanza stanza) { + final String from = stanza.getAttribute("from"); + if (from == null) { return false; - } else { + } + try { + Jid.ofEscaped(from); return true; + } catch (IllegalArgumentException e) { + return false; } } }
\ No newline at end of file |