pidgin: a743f7b2: Validate IPv6 identifiers in the domain ...
darkrain42 at pidgin.im
darkrain42 at pidgin.im
Sat Jul 11 03:50:23 EDT 2009
-----------------------------------------------------------------
Revision: a743f7b2086257b37f218802f4ae61803cf5ff01
Ancestor: 9bc55bda447e59bff67f0dbfd1b01348cb78f5ee
Author: darkrain42 at pidgin.im
Date: 2009-07-11T07:47:07
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/a743f7b2086257b37f218802f4ae61803cf5ff01
Modified files:
libpurple/protocols/jabber/chat.c
libpurple/protocols/jabber/jutil.c
libpurple/protocols/jabber/jutil.h
libpurple/tests/test_jabber_jutil.c
ChangeLog:
Validate IPv6 identifiers in the domain portion of a JID.
-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/chat.c 55a1e75d321052a54d298e696d8559d5a6c90ac5
+++ libpurple/protocols/jabber/chat.c b214f88f5370671384d42fc39492fdc9ec2089d3
@@ -235,7 +235,7 @@ void jabber_chat_join(PurpleConnection *
purple_serv_got_join_chat_failed(gc, data);
g_free(buf);
return;
- } else if(!jabber_nameprep_validate(server)) {
+ } else if(!jabber_domain_validate(server)) {
char *buf = g_strdup_printf(_("%s is not a valid server name"), server);
purple_notify_error(gc, _("Invalid Server Name"),
_("Invalid Server Name"), buf);
============================================================
--- libpurple/protocols/jabber/jutil.c 8cff93dea2f6105c3497fc5d4d9ac91664751c3f
+++ libpurple/protocols/jabber/jutil.c 72853c7c8aa5c03fd177811a6bac57004b25857e
@@ -54,7 +54,7 @@ gboolean jabber_nodeprep_validate(const
return TRUE;
}
-gboolean jabber_nameprep_validate(const char *str)
+gboolean jabber_domain_validate(const char *str)
{
const char *c;
@@ -64,11 +64,24 @@ gboolean jabber_nameprep_validate(const
if(strlen(str) > 1023)
return FALSE;
- /*
- * TODO: An IPv6 address of the form [2001:470:1f05:d58::2] is also
- * a valid XMPP domain portion.
- */
c = str;
+
+ if (*c == '[') {
+ /* Check if str is a valid IPv6 identifier */
+ const gchar *end_bracket = strstr(c, "]");
+ gboolean valid = FALSE;
+
+ if (!end_bracket || *(end_bracket + 1) != '\0')
+ return FALSE;
+
+ /* Ugly, but in-place */
+ *(gchar *)end_bracket = '\0';
+ valid = purple_ipv6_address_is_valid(c + 1);
+ *(gchar *)end_bracket = ']';
+
+ return valid;
+ }
+
while(c && *c) {
gunichar ch = g_utf8_get_char(c);
/* The list of characters allowed in domain names is pretty small */
@@ -271,7 +284,7 @@ jabber_id_new(const char *str)
/* and finally the jabber nodeprep */
if(!jabber_nodeprep_validate(jid->node) ||
- !jabber_nameprep_validate(jid->domain) ||
+ !jabber_domain_validate(jid->domain) ||
!jabber_resourceprep_validate(jid->resource)) {
jabber_id_free(jid);
return NULL;
============================================================
--- libpurple/protocols/jabber/jutil.h 4e4ee2cce668f54474866c4db1a5501527bc2d6d
+++ libpurple/protocols/jabber/jutil.h b646920f1c7d9a9d20ec8c613ab269a337584f5f
@@ -45,8 +45,7 @@ gboolean jabber_nodeprep_validate(const
gboolean jabber_is_own_account(JabberStream *js, const char *jid);
gboolean jabber_nodeprep_validate(const char *);
-/* TODO: This needs to be named jabber_domain_validate and handle IPv6/IDNA. */
-gboolean jabber_nameprep_validate(const char *);
+gboolean jabber_domain_validate(const char *);
gboolean jabber_resourceprep_validate(const char *);
PurpleConversation *jabber_find_unnormalized_conv(const char *name, PurpleAccount *account);
============================================================
--- libpurple/tests/test_jabber_jutil.c bfaed25538482aed17a715318349decdecab1e05
+++ libpurple/tests/test_jabber_jutil.c acdaf7d1a5d5f8b57f5b90fed9555cc607e4a1e3
@@ -100,11 +100,9 @@ START_TEST(test_jabber_id_new)
assert_valid_jid("mark.doliner@???.org");
assert_valid_jid("nick@??.????.net");
assert_valid_jid("paul at 10.0.42.230/s");
-#if 0
-/* Uncomment these when jabber_domain_validate supports IPv6 addresses */
assert_valid_jid("paul@[::1]"); /* IPv6 */
assert_valid_jid("paul@[2001:470:1f05:d58::2]");
-#endif
+ assert_valid_jid("paul@[2001:470:1f05:d58::2]/foo");
assert_invalid_jid("@gmail.com");
assert_invalid_jid("@@gmail.com");
@@ -117,6 +115,8 @@ START_TEST(test_jabber_id_new)
assert_invalid_jid("mark.doliner at gmail_stuff.org");
assert_invalid_jid("mark.doliner at gmail[stuff.org");
assert_invalid_jid("mark.doliner at gmail\\stuff.org");
+ assert_invalid_jid("paul@[::1]124");
+ assert_invalid_jid("paul at 2[::1]124/as");
}
END_TEST
More information about the Commits
mailing list