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/stanza.vala | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'xmpp-vala/src/module/stanza.vala') diff --git a/xmpp-vala/src/module/stanza.vala b/xmpp-vala/src/module/stanza.vala index abdc33e9..f4e40f84 100644 --- a/xmpp-vala/src/module/stanza.vala +++ b/xmpp-vala/src/module/stanza.vala @@ -18,7 +18,13 @@ public class Stanza : Object { string? from_attribute = stanza.get_attribute(ATTRIBUTE_FROM); // "when a client receives a stanza that does not include a 'from' attribute, it MUST assume that the stanza // is from the user's account on the server." (RFC6120 8.1.2.1) - if (from_attribute != null) return from_ = Jid.parse(from_attribute); + if (from_attribute != null) { + try { + return from_ = new Jid(from_attribute); + } catch (InvalidJidError e) { + warning("Ignoring invalid from Jid: %s", e.message); + } + } if (my_jid != null) { return my_jid.bare_jid; } @@ -37,7 +43,12 @@ public class Stanza : Object { string? to_attribute = stanza.get_attribute(ATTRIBUTE_TO); // "if the stanza does not include a 'to' address then the client MUST treat it as if the 'to' address were // included with a value of the client's full JID." (RFC6120 8.1.1.1) - return to_attribute == null ? my_jid : to_ = Jid.parse(to_attribute); + try { + return to_attribute == null ? my_jid : to_ = new Jid(to_attribute); + } catch (InvalidJidError e) { + warning("Ignoring invalid to Jid: %s", e.message); + } + return my_jid; } set { stanza.set_attribute(ATTRIBUTE_TO, value.to_string()); } } -- cgit v1.2.3-54-g00ecf