diff options
author | Wilmer van der Gaast <wilmer@gaast.net> | 2010-04-07 03:27:55 +0100 |
---|---|---|
committer | Wilmer van der Gaast <wilmer@gaast.net> | 2010-04-07 03:27:55 +0100 |
commit | 33b306eaaa3e05cbc5d196d0d2f0b741ff11a9e6 (patch) | |
tree | 84ff04bfae5fcd88b3b695031ecccbe7668f2acd | |
parent | 7815a2b57887751a7e026747b27abea04b13abae (diff) |
Don't allow non-8-bit character sets like utf-16 which completely break the
IRC protocol. (Happened to at least two public server users by now and it
renders the accounts useless without manual intervention.)
-rw-r--r-- | irc.c | 17 |
1 files changed, 14 insertions, 3 deletions
@@ -51,18 +51,29 @@ static char *set_eval_password( set_t *set, char *value ) static char *set_eval_charset( set_t *set, char *value ) { irc_t *irc = set->data; + char *test; + gsize test_bytes = 0; GIConv ic, oc; if( g_strcasecmp( value, "none" ) == 0 ) value = g_strdup( "utf-8" ); - if( ( ic = g_iconv_open( "utf-8", value ) ) == (GIConv) -1 ) + if( ( oc = g_iconv_open( value, "utf-8" ) ) == (GIConv) -1 ) { return NULL; } - if( ( oc = g_iconv_open( value, "utf-8" ) ) == (GIConv) -1 ) + if( ( test = g_convert_with_iconv( " ", 1, oc, NULL, &test_bytes, NULL ) ) == NULL || + test_bytes > 1 ) + { + g_free( test ); + g_iconv_close( oc ); + irc_usermsg( irc, "Unsupported character set: The IRC protocol " + "only supports 8-bit character sets." ); + return NULL; + } + if( ( ic = g_iconv_open( "utf-8", value ) ) == (GIConv) -1 ) { - g_iconv_close( ic ); + g_iconv_close( oc ); return NULL; } |