diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-11-15 18:25:15 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-11-15 18:25:15 +0000 |
commit | 4d436a67f1c15b4c1e47864a7d7f267162a7da79 (patch) | |
tree | f504e902c083d5f4324259c855cfce55047e53e3 /src/libutil/str_util.c | |
parent | c234e5bc9c8b19625009d3925f37875e5fa820d4 (diff) | |
download | rspamd-4d436a67f1c15b4c1e47864a7d7f267162a7da79.tar.gz rspamd-4d436a67f1c15b4c1e47864a7d7f267162a7da79.zip |
[Fix] Fix issues found
Diffstat (limited to 'src/libutil/str_util.c')
-rw-r--r-- | src/libutil/str_util.c | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/libutil/str_util.c b/src/libutil/str_util.c index dd1b139d8..9f4ad1cb0 100644 --- a/src/libutil/str_util.c +++ b/src/libutil/str_util.c @@ -3071,30 +3071,31 @@ rspamd_str_make_utf_valid (const guchar *src, gsize slen, } p = src; - dlen = slen; + dlen = slen + 1; /* As we add '\0' */ /* Check space required */ - while (remain > 0 && (err_offset = rspamd_fast_utf8_validate (p, remain) > 0)) { + while (remain > 0 && (err_offset = rspamd_fast_utf8_validate (p, remain)) > 0) { gint i = 0; + err_offset --; /* As it returns it 1 indexed */ p += err_offset; remain -= err_offset; dlen += err_offset; - /* Each invalid character of input requires 3 bytes of output */ + /* Each invalid character of input requires 3 bytes of output (+2 bytes) */ while (i < remain) { - gint old_i = i; U8_NEXT (p, i, remain, uc); if (uc < 0) { - dlen += 3; + dlen += 2; } else { - p += old_i; - remain -= old_i; break; } } + + p += i; + remain -= i; } if (pool) { @@ -3108,8 +3109,9 @@ rspamd_str_make_utf_valid (const guchar *src, gsize slen, d = dst; remain = slen; - while (remain > 0 && (err_offset = rspamd_fast_utf8_validate (p, remain) > 0)) { + while (remain > 0 && (err_offset = rspamd_fast_utf8_validate (p, remain)) > 0) { /* Copy valid */ + err_offset --; /* As it returns it 1 indexed */ memcpy (d, p, err_offset); d += err_offset; @@ -3130,8 +3132,7 @@ rspamd_str_make_utf_valid (const guchar *src, gsize slen, } else { /* Adjust p and remaining stuff and go to the outer cycle */ - p += old_i; - remain -= old_i; + i = old_i; break; } } @@ -3139,6 +3140,8 @@ rspamd_str_make_utf_valid (const guchar *src, gsize slen, * Now p is the first valid utf8 character and remain is the rest of the string * so we can continue our loop */ + p += i; + remain -= i; } if (err_offset == 0 && remain > 0) { |