check if jid was valid before parsing muc status or event msgs

This commit is contained in:
Daniel Gultsch 2018-04-29 09:33:20 +02:00
parent 3011f875eb
commit d0c88e6293
2 changed files with 16 additions and 6 deletions

View File

@ -303,7 +303,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
Log.e(Config.LOGTAG, account.getJid().asBareJid() + ": received groupchat (" + from + ") message on regular MAM request. skipping");
return;
}
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;
@ -645,7 +645,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 {
@ -746,12 +746,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);

View File

@ -31,6 +31,7 @@ package eu.siacs.conversations.xmpp;
import android.support.annotation.NonNull;
import eu.siacs.conversations.xmpp.stanzas.AbstractStanza;
import rocks.xmpp.addr.Jid;
public class InvalidJid implements Jid {
@ -140,10 +141,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;
}
}
}