]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/3.10.101/lib-ucs2_string-correct-ucs2-utf8-conversion.patch
3.18-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 3.10.101 / lib-ucs2_string-correct-ucs2-utf8-conversion.patch
CommitLineData
6818d0ef
GKH
1From a68075908a37850918ad96b056acc9ac4ce1bd90 Mon Sep 17 00:00:00 2001
2From: Jason Andryuk <jandryuk@gmail.com>
3Date: Fri, 12 Feb 2016 23:13:33 +0000
4Subject: lib/ucs2_string: Correct ucs2 -> utf8 conversion
5
6From: Jason Andryuk <jandryuk@gmail.com>
7
8commit a68075908a37850918ad96b056acc9ac4ce1bd90 upstream.
9
10The comparisons should be >= since 0x800 and 0x80 require an additional bit
11to store.
12
13For the 3 byte case, the existing shift would drop off 2 more bits than
14intended.
15
16For the 2 byte case, there should be 5 bits bits in byte 1, and 6 bits in
17byte 2.
18
19Signed-off-by: Jason Andryuk <jandryuk@gmail.com>
20Reviewed-by: Laszlo Ersek <lersek@redhat.com>
21Cc: Peter Jones <pjones@redhat.com>
22Cc: Matthew Garrett <mjg59@coreos.com>
23Cc: "Lee, Chun-Yi" <jlee@suse.com>
24Signed-off-by: Matt Fleming <matt@codeblueprint.co.uk>
25Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
26
27---
28 lib/ucs2_string.c | 14 +++++++-------
29 1 file changed, 7 insertions(+), 7 deletions(-)
30
31--- a/lib/ucs2_string.c
32+++ b/lib/ucs2_string.c
33@@ -59,9 +59,9 @@ ucs2_utf8size(const ucs2_char_t *src)
34 for (i = 0; i < ucs2_strlen(src); i++) {
35 u16 c = src[i];
36
37- if (c > 0x800)
38+ if (c >= 0x800)
39 j += 3;
40- else if (c > 0x80)
41+ else if (c >= 0x80)
42 j += 2;
43 else
44 j += 1;
45@@ -88,19 +88,19 @@ ucs2_as_utf8(u8 *dest, const ucs2_char_t
46 for (i = 0; maxlength && i < limit; i++) {
47 u16 c = src[i];
48
49- if (c > 0x800) {
50+ if (c >= 0x800) {
51 if (maxlength < 3)
52 break;
53 maxlength -= 3;
54 dest[j++] = 0xe0 | (c & 0xf000) >> 12;
55- dest[j++] = 0x80 | (c & 0x0fc0) >> 8;
56+ dest[j++] = 0x80 | (c & 0x0fc0) >> 6;
57 dest[j++] = 0x80 | (c & 0x003f);
58- } else if (c > 0x80) {
59+ } else if (c >= 0x80) {
60 if (maxlength < 2)
61 break;
62 maxlength -= 2;
63- dest[j++] = 0xc0 | (c & 0xfe0) >> 5;
64- dest[j++] = 0x80 | (c & 0x01f);
65+ dest[j++] = 0xc0 | (c & 0x7c0) >> 6;
66+ dest[j++] = 0x80 | (c & 0x03f);
67 } else {
68 maxlength -= 1;
69 dest[j++] = c & 0x7f;