aboutsummaryrefslogtreecommitdiffstats
path: root/src/libutil
diff options
context:
space:
mode:
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/util.c18
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';
}