utf8: make sure to honor the array length properly

Right now the input side can give partial utf8 input, and that showed
that we didn't properly handle that case.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
diff --git a/utf8.c b/utf8.c
index 6276b13..3bffd1e 100644
--- a/utf8.c
+++ b/utf8.c
@@ -41,13 +41,13 @@
 	/* Invalid? Do it as a single byte Latin1 */
 	if (bytes > 6)
 		return 1;
+	if (bytes > len)
+		return 1;
 
 	value = c & (mask-1);
 
 	/* Ok, do the bytes */
 	for (i = 1; i < bytes; i++) {
-		if (i > len)
-			return 1;
 		c = line[i];
 		if ((c & 0xc0) != 0x80)
 			return 1;