diff options
author | Will Thompson <will.thompson@collabora.co.uk> | 2010-06-14 13:43:53 +0100 |
---|---|---|
committer | Will Thompson <will.thompson@collabora.co.uk> | 2010-06-14 13:43:53 +0100 |
commit | 87a76cb893a2b950d99bf2a24c11b4c40bff24cf (patch) | |
tree | 3402d9729cee72f59088e6a781c53fb9993103e5 | |
parent | 138b04b3a2c2b3b3812ed3ec0d81ae6857312b1f (diff) |
Accept valid Unicode domains
Previously we did not accept any non-ASCII domains, which meant we
dropped perfectly valid messages from perfectly valid contacts. :o
This patch accepts any non-ASCII characters in domains. This is still
not right — for instance, spaces in domains are properly rejected, but
non-breaking spaces are improperly accepted — but it's better than no
validation at all (which was my previous attempt at fixing this) and
avoids us dropping messages.
(Taken from cba01d1 in Wocky, without the test case that commit added.)
-rw-r--r-- | src/util.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/util.c b/src/util.c index c839b240c..af08c1fcd 100644 --- a/src/util.c +++ b/src/util.c @@ -437,9 +437,11 @@ validate_jid_node (const gchar *node) 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. + /* XXX: This doesn't do proper validation: it checks the character + * range for ASCII characters, but lets through any non-ASCII characters. See + * the ifdef-d out tests in wocky-jid-validation-test.c for examples of + * erroneously accepted JIDs. In theory, we check that the domain is a + * well-formed IDN or an IPv4/IPv6 address literal. * * See RFC 3920 §3.2. */ @@ -447,8 +449,13 @@ validate_jid_domain (const gchar *domain) const gchar *c; for (c = domain; *c; c++) - if (!g_ascii_isalnum (*c) && !strchr (":-.", *c)) - return FALSE; + { + if ((unsigned char) *c >= 0x7F) + continue; + + if (!g_ascii_isalnum (*c) && !strchr (":-.", *c)) + return FALSE; + } return TRUE; } |