diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-04-02 14:09:59 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-04-02 14:26:34 +0100 |
commit | 2c0c7937ec6cf30e17e8e418939a8cba3cce7714 (patch) | |
tree | 02d5fac4efc9cda90badab42cf844ab6bc3900da /src/libutil | |
parent | c09696d74506cf9bb54a8a5b792f7686e7cb9788 (diff) | |
download | rspamd-2c0c7937ec6cf30e17e8e418939a8cba3cce7714.tar.gz rspamd-2c0c7937ec6cf30e17e8e418939a8cba3cce7714.zip |
Fix broken unicode sequences.
Diffstat (limited to 'src/libutil')
-rw-r--r-- | src/libutil/util.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/libutil/util.c b/src/libutil/util.c index f64fe2401..259e242e3 100644 --- a/src/libutil/util.c +++ b/src/libutil/util.c @@ -735,7 +735,7 @@ void rspamd_str_lc_utf8 (gchar *str, guint size) { const gchar *s = str, *p; - gchar *d = str; + gchar *d = str, tst[6]; gint remain = size; gint r; gunichar uc; @@ -749,12 +749,24 @@ rspamd_str_lc_utf8 (gchar *str, guint size) break; } - r = g_unichar_to_utf8 (uc, d); - g_assert (remain >= r); + if (remain >= 6) { + r = g_unichar_to_utf8 (uc, d); + } + else { + /* We must be cautious here to avoid broken unicode being append */ + r = g_unichar_to_utf8 (uc, tst); + if (r > remain) { + break; + } + else { + memcpy (d, tst, r); + } + } remain -= r; s = p; d += r; } + *d = '\0'; } |