dovecot: uni_utf8_to_decomposed_titlecase(): If we encounter inv...

dovecot at dovecot.org dovecot at dovecot.org
Sat Dec 8 15:55:13 EET 2007


details:   http://hg.dovecot.org/dovecot/rev/edd296d164db
changeset: 6953:edd296d164db
user:      Timo Sirainen <tss at iki.fi>
date:      Sat Dec 08 15:55:09 2007 +0200
description:
uni_utf8_to_decomposed_titlecase(): If we encounter invalid UTF-8 input,
skip over it instead of aborting directly.

diffstat:

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

diffs (29 lines):

diff -r 08e4d7efcd6a -r edd296d164db src/lib/unichar.c
--- a/src/lib/unichar.c	Sat Dec 08 15:53:15 2007 +0200
+++ b/src/lib/unichar.c	Sat Dec 08 15:55:09 2007 +0200
@@ -266,11 +266,14 @@ int uni_utf8_to_decomposed_titlecase(con
 	const unsigned char *input = _input;
 	unsigned int bytes;
 	unichar_t chr;
+	int ret = 0;
 
 	while (max_len > 0 && *input != '\0') {
 		if (uni_utf8_get_char_n(input, max_len, &chr) <= 0) {
-			/* invalid input */
-			return -1;
+			/* invalid input. try the next byte. */
+			ret = -1;
+			input++; max_len--;
+			continue;
 		}
 		bytes = uni_utf8_char_bytes(*input);
 		input += bytes;
@@ -283,7 +286,7 @@ int uni_utf8_to_decomposed_titlecase(con
 			 !uni_ucs4_decompose_multi_utf8(chr, output))
 			uni_ucs4_to_utf8_c(chr, output);
 	}
-	return 0;
+	return ret;
 }
 
 static inline unsigned int


More information about the dovecot-cvs mailing list