]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - 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
1 From a68075908a37850918ad96b056acc9ac4ce1bd90 Mon Sep 17 00:00:00 2001
2 From: Jason Andryuk <jandryuk@gmail.com>
3 Date: Fri, 12 Feb 2016 23:13:33 +0000
4 Subject: lib/ucs2_string: Correct ucs2 -> utf8 conversion
5
6 From: Jason Andryuk <jandryuk@gmail.com>
7
8 commit a68075908a37850918ad96b056acc9ac4ce1bd90 upstream.
9
10 The comparisons should be >= since 0x800 and 0x80 require an additional bit
11 to store.
12
13 For the 3 byte case, the existing shift would drop off 2 more bits than
14 intended.
15
16 For the 2 byte case, there should be 5 bits bits in byte 1, and 6 bits in
17 byte 2.
18
19 Signed-off-by: Jason Andryuk <jandryuk@gmail.com>
20 Reviewed-by: Laszlo Ersek <lersek@redhat.com>
21 Cc: Peter Jones <pjones@redhat.com>
22 Cc: Matthew Garrett <mjg59@coreos.com>
23 Cc: "Lee, Chun-Yi" <jlee@suse.com>
24 Signed-off-by: Matt Fleming <matt@codeblueprint.co.uk>
25 Signed-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;