Mercurial > dovecot > original-hg > dovecot-1.2
changeset 9602:cc7aa7a4dd6d HEAD
UTF-8 string validity was still checked incorrectly.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 19 Aug 2010 18:06:22 +0100 |
parents | 70fa6178380e |
children | 5efba9f9f0a7 |
files | src/lib/unichar.c src/lib/unichar.h |
diffstat | 2 files changed, 5 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib/unichar.c Thu Aug 19 18:36:09 2010 +0100 +++ b/src/lib/unichar.c Thu Aug 19 18:06:22 2010 +0100 @@ -309,7 +309,7 @@ static inline unsigned int is_valid_utf8_seq(const unsigned char *input, unsigned int size) { - size_t i, len; + unsigned int i, len; len = uni_utf8_char_bytes(input[0]); if (unlikely(len > size || len == 1)) @@ -318,8 +318,7 @@ /* the rest of the chars should be in 0x80..0xbf range. anything else is start of a sequence or invalid */ for (i = 1; i < len; i++) { - if (unlikely(uni_utf8_char_bytes(input[i]) != len-i || - input[i] < 0x80 || input[i] >= 0xbf)) + if (unlikely(input[i] < 0x80 || input[i] > 0xbf)) return 0; } return len;
--- a/src/lib/unichar.h Thu Aug 19 18:36:09 2010 +0100 +++ b/src/lib/unichar.h Thu Aug 19 18:06:22 2010 +0100 @@ -43,8 +43,9 @@ /* Returns UTF-8 string length with maximum input size. */ unsigned int uni_utf8_strlen_n(const void *input, size_t size) ATTR_PURE; -/* Returns the number of bytes belonging to this partial UTF-8 character. - Invalid input is returned with length 1. */ +/* Returns the number of bytes belonging to this UTF-8 character. The given + parameter is the first byte of the UTF-8 sequence. Invalid input is + returned with length 1. */ static inline unsigned int ATTR_CONST uni_utf8_char_bytes(char chr) {