]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
UTF-8 string validity was still checked incorrectly.
authorTimo Sirainen <tss@iki.fi>
Thu, 19 Aug 2010 17:06:22 +0000 (18:06 +0100)
committerTimo Sirainen <tss@iki.fi>
Thu, 19 Aug 2010 17:06:22 +0000 (18:06 +0100)
src/lib/unichar.c
src/lib/unichar.h

index 9d5d406f6ac5f2d6e80d119dd704fc48b1c5ad62..961b2fe96a2d1ffc8e9453fb547ccefb8f311856 100644 (file)
@@ -316,7 +316,7 @@ int uni_utf8_to_decomposed_titlecase(const void *_input, size_t max_len,
 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))
@@ -325,8 +325,7 @@ is_valid_utf8_seq(const unsigned char *input, unsigned int size)
        /* 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;
index 5dfaf8e70fb1789af28b2463b1a561140e118ae6..3132bd1bec69c3faf357c039331a69b51ce3ac38 100644 (file)
@@ -43,8 +43,9 @@ int uni_utf8_get_char_n(const void *input, size_t max_len, unichar_t *chr_r);
 /* 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)
 {