dovecot: uni_utf8_get_valid_data(): Check for invalid UTF-8 better.

dovecot at dovecot.org dovecot at dovecot.org
Mon Jan 14 06:44:43 EET 2008


details:   http://hg.dovecot.org/dovecot/rev/0c1d5a814368
changeset: 7157:0c1d5a814368
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Jan 14 06:44:38 2008 +0200
description:
uni_utf8_get_valid_data(): Check for invalid UTF-8 better.

diffstat:

1 file changed, 4 insertions(+), 3 deletions(-)
src/lib/unichar.c |    7 ++++---

diffs (19 lines):

diff -r 5dda06c19eb1 -r 0c1d5a814368 src/lib/unichar.c
--- a/src/lib/unichar.c	Sat Jan 12 11:47:12 2008 +0200
+++ b/src/lib/unichar.c	Mon Jan 14 06:44:38 2008 +0200
@@ -295,11 +295,12 @@ is_valid_utf8_seq(const unsigned char *i
 	size_t i, len;
 
 	len = uni_utf8_char_bytes(input[0]);
-	if (unlikely(len > size))
+	if (unlikely(len > size || len == 1))
 		return 0;
 
-	for (i = 0; i < len; i++) {
-		if (unlikely(uni_utf8_char_bytes(input[i]) != len-i))
+	for (i = 1; i < len; i++) {
+		if (unlikely(uni_utf8_char_bytes(input[i]) != len-i ||
+			     input[i] < 192-2))
 			return 0;
 	}
 	return len;


More information about the dovecot-cvs mailing list