From a0a956ee0878d24bd06be7f5d75dc4ccd4e7901d Mon Sep 17 00:00:00 2001 From: Marvin W Date: Sun, 22 Dec 2019 04:10:53 +0100 Subject: Properly check Jids everywhere --- xmpp-vala/src/module/bind.vala | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'xmpp-vala/src/module/bind.vala') diff --git a/xmpp-vala/src/module/bind.vala b/xmpp-vala/src/module/bind.vala index a3b0762b..89398bfb 100644 --- a/xmpp-vala/src/module/bind.vala +++ b/xmpp-vala/src/module/bind.vala @@ -5,11 +5,11 @@ namespace Xmpp.Bind { public class Module : XmppStreamNegotiationModule { public static ModuleIdentity IDENTITY = new ModuleIdentity(NS_URI, "bind_module"); - public string requested_resource { get; set; } + public string? requested_resource { get; set; } public signal void bound_to_resource(XmppStream stream, Jid my_jid); - public Module(string requested_resource) { + public Module(string? requested_resource) { this.requested_resource = requested_resource; } @@ -18,9 +18,13 @@ namespace Xmpp.Bind { if (flag == null || flag.finished) return; if (iq.type_ == Iq.Stanza.TYPE_RESULT) { - flag.my_jid = Jid.parse(iq.stanza.get_subnode("jid", NS_URI, true).get_string_content()); - flag.finished = true; - bound_to_resource(stream, flag.my_jid); + try { + flag.my_jid = new Jid(iq.stanza.get_subnode("jid", NS_URI, true).get_string_content()); + flag.finished = true; + bound_to_resource(stream, flag.my_jid); + } catch (InvalidJidError e) { + warning("Received invalid Jid when binding: %s", e.message); + } } } @@ -32,7 +36,9 @@ namespace Xmpp.Bind { if (bind != null) { var flag = new Flag(); StanzaNode bind_node = new StanzaNode.build("bind", NS_URI).add_self_xmlns(); - bind_node.put_node(new StanzaNode.build("resource", NS_URI).put_node(new StanzaNode.text(requested_resource))); + if (requested_resource != null) { + bind_node.put_node(new StanzaNode.build("resource", NS_URI).put_node(new StanzaNode.text(requested_resource))); + } stream.get_module(Iq.Module.IDENTITY).send_iq(stream, new Iq.Stanza.set(bind_node), iq_response_stanza); stream.add_flag(flag); } -- cgit v1.2.3-54-g00ecf