[telepathy-gabble/master] gabble_decode_jid(): check for invalid characters in node and domain
Dafydd Harries
dafydd.harries at collabora.co.uk
Tue Aug 25 11:30:50 PDT 2009
---
src/util.c | 34 +++++++++++++++++++++++++++++++++-
tests/test-jid-decode.c | 3 +++
2 files changed, 36 insertions(+), 1 deletions(-)
diff --git a/src/util.c b/src/util.c
index 9985f0d..97c651a 100644
--- a/src/util.c
+++ b/src/util.c
@@ -406,6 +406,36 @@ lm_message_build_with_sub_type (const gchar *to, LmMessageType type,
return msg;
}
+static gboolean
+validate_jid_node (const gchar *node)
+{
+ const gchar *c;
+
+ for (c = node; *c; c++)
+ if (strchr ("\"&'/:<>@", *c))
+ /* RFC 3920 §A.5 */
+ return FALSE;
+
+ return TRUE;
+}
+
+static gboolean
+validate_jid_domain (const gchar *domain)
+{
+ /* XXX: This doesn't do proper validation, it just checks the character
+ * range. In theory, we check that the domain is a well-formed IDN or
+ * an IPv4/IPv6 address literal.
+ */
+
+ const gchar *c;
+
+ for (c = domain; *c; c++)
+ if (!g_ascii_isalnum (*c) && !strchr (":-.", *c))
+ return FALSE;
+
+ return TRUE;
+}
+
/**
* gabble_decode_jid
*
@@ -474,7 +504,9 @@ gabble_decode_jid (const gchar *jid,
* non-empty.
*/
if (*tmp_domain == '\0' ||
- (tmp_node != NULL && *tmp_node == '\0') ||
+ !validate_jid_domain (tmp_domain) ||
+ (tmp_node != NULL &&
+ (*tmp_node == '\0' || !validate_jid_node (tmp_node))) ||
(tmp_resource != NULL && *tmp_resource == '\0'))
{
g_free (tmp_jid);
diff --git a/tests/test-jid-decode.c b/tests/test-jid-decode.c
index be676cf..b72015c 100644
--- a/tests/test-jid-decode.c
+++ b/tests/test-jid-decode.c
@@ -48,6 +48,9 @@ main (void)
test_fail ("@bar");
test_fail ("foo at bar/");
test_pass ("Foo at Bar/Baz", "foo", "bar", "Baz");
+ test_fail ("foo@@");
+ test_fail ("foo&bar at baz");
+ test_pass ("foo at bar/foo at bar/foo at bar", "foo", "bar", "foo at bar/foo at bar");
return 0;
}
--
1.5.6.5
More information about the telepathy-commits
mailing list