Browse code

glib: Fix for CVE-2018-16428 and CVE-2018-16429

Change-Id: I027e418a0be95a17e356c9b10388f5e5eb7619e7
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/6087
Reviewed-by: Sharath George
Tested-by: gerrit-photon <photon-checkins@vmware.com>

Keerthana K authored on 2018/11/03 04:28:45
Showing 3 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,81 @@
0
+
1
+m fccef3cc822af74699cca84cd202719ae61ca3b9 Mon Sep 17 00:00:00 2001
2
+From: Philip Withnall <withnall@endlessm.com>
3
+Date: Mon, 30 Jul 2018 18:33:39 +0100
4
+Subject: [PATCH] gmarkup: Fix crash in error handling path for closing
5
+ elements
6
+MIME-Version: 1.0
7
+Content-Type: text/plain; charset=UTF-8
8
+Content-Transfer-Encoding: 8bit
9
+
10
+If something which looks like a closing tag is left unfinished, but
11
+isn’t paired to an opening tag in the document, the error handling code
12
+would do a null pointer dereference. Avoid that, at the cost of
13
+introducing a new translatable error message.
14
+
15
+Includes a test case, courtesy of pdknsk.
16
+
17
+Signed-off-by: Philip Withnall <withnall@endlessm.com>
18
+
19
+https://gitlab.gnome.org/GNOME/glib/issues/1461
20
+---
21
+glib/gmarkup.c                      | 11 ++++++++---
22
+ glib/tests/Makefile.am              |  2 +-
23
+ glib/tests/markups/fail-51.expected |  1 +
24
+ glib/tests/markups/fail-51.gmarkup  |  1 +
25
+ 4 files changed, 11 insertions(+), 4 deletions(-)
26
+ create mode 100644 glib/tests/markups/fail-51.expected
27
+ create mode 100644 glib/tests/markups/fail-51.gmarkup
28
+
29
+diff --git a/glib/gmarkup.c b/glib/gmarkup.c
30
+index ed30ed2..a159d7b 100644
31
+--- a/glib/gmarkup.c
32
+@@ -1832,9 +1832,14 @@ g_markup_parse_context_end_parse (GMarkupParseContext  *context,
33
+     case STATE_AFTER_CLOSE_TAG_SLASH:
34
+     case STATE_INSIDE_CLOSE_TAG_NAME:
35
+     case STATE_AFTER_CLOSE_TAG_NAME:
36
+-      set_error (context, error, G_MARKUP_ERROR_PARSE,
37
+-                 _("Document ended unexpectedly inside the close tag for "
38
+-                   "element '%s'"), current_element (context));
39
++      if (context->tag_stack != NULL)
40
++        set_error (context, error, G_MARKUP_ERROR_PARSE,
41
++                   _("Document ended unexpectedly inside the close tag for "
42
++                     "element '%s'"), current_element (context));
43
++      else
44
++        set_error (context, error, G_MARKUP_ERROR_PARSE,
45
++                   _("Document ended unexpectedly inside the close tag for an "
46
++                     "unopened element"));
47
+       break;
48
+ 
49
+     case STATE_INSIDE_PASSTHROUGH:
50
+diff --git a/glib/tests/Makefile.am b/glib/tests/Makefile.am
51
+index b3983d3..a690064 100644
52
+--- a/glib/tests/Makefile.am
53
+@@ -155,7 +155,7 @@ markup_tests = \
54
+ 	fail-31 fail-32 fail-33 fail-34 fail-35 \
55
+ 	fail-36 fail-37 fail-38 fail-39 fail-40 \
56
+ 	fail-41 fail-42 fail-43 fail-44 fail-45 \
57
+-	fail-46 fail-47 fail-48 fail-49 \
58
++	fail-46 fail-47 fail-48 fail-49 fail-51 \
59
+ 	valid-1 valid-2 valid-3 valid-4 valid-5 \
60
+ 	valid-6 valid-7 valid-8 valid-9 valid-10 \
61
+ 	valid-11 valid-12 valid-13 valid-14 valid-15 \
62
+diff --git a/glib/tests/markups/fail-51.expected b/glib/tests/markups/fail-51.expected
63
+new file mode 100644
64
+index 0000000..1c7e8d4
65
+--- /dev/null
66
+@@ -0,0 +1 @@
67
++ERROR Error on line 1 char 5: Document ended unexpectedly inside the close tag for an unopened element
68
+diff --git a/glib/tests/markups/fail-51.gmarkup b/glib/tests/markups/fail-51.gmarkup
69
+new file mode 100644
70
+index 0000000..860e1e6
71
+--- /dev/null
72
+@@ -0,0 +1 @@
73
++</0<
74
+\ No newline at end of file
75
+-- 
76
+2.7.4
0 77
new file mode 100644
... ...
@@ -0,0 +1,87 @@
0
+From cec71705406f0b2790422f0c1aa0ff3b4b464b1b Mon Sep 17 00:00:00 2001
1
+From: Philip Withnall <withnall@endlessm.com>
2
+Date: Mon, 30 Jul 2018 18:10:25 +0100
3
+Subject: [PATCH] gmarkup: Fix unvalidated UTF-8 read in markup parsing error
4
+ paths
5
+MIME-Version: 1.0
6
+Content-Type: text/plain; charset=UTF-8
7
+Content-Transfer-Encoding: 8bit
8
+
9
+When formatting the error messages for markup parsing errors, the parser
10
+was unconditionally reading a UTF-8 character from the input buffer —
11
+but the buffer might end with a partial code sequence, resulting in
12
+reading off the end of the buffer by up to three bytes.
13
+
14
+Fix this and add a test case, courtesy of pdknsk.
15
+
16
+Signed-off-by: Philip Withnall <withnall@endlessm.com>
17
+
18
+---
19
+ glib/gmarkup.c                      | 14 +++++++++++++-
20
+ glib/tests/Makefile.am              |  3 ++-
21
+ glib/tests/markups/fail-50.expected |  1 +
22
+ glib/tests/markups/fail-50.gmarkup  |  1 +
23
+ 4 files changed, 17 insertions(+), 2 deletions(-)
24
+ create mode 100644 glib/tests/markups/fail-50.expected
25
+ create mode 100644 glib/tests/markups/fail-50.gmarkup
26
+
27
+diff --git a/glib/gmarkup.c b/glib/gmarkup.c
28
+index a159d7b..a2b1ed0 100644
29
+--- a/glib/gmarkup.c
30
+@@ -557,11 +557,23 @@ char_str (gunichar c,
31
+   return buf;
32
+ }
33
+ 
34
++/* Format the next UTF-8 character as a gchar* for printing in error output
35
++ * when we encounter a syntax error. This correctly handles invalid UTF-8,
36
++ * emitting it as hex escapes. */
37
+ static gchar*
38
+ utf8_str (const gchar *utf8,
39
+           gchar       *buf)
40
+ {
41
+-  char_str (g_utf8_get_char (utf8), buf);
42
++  gunichar c = g_utf8_get_char_validated (utf8, -1);
43
++  if (c == (gunichar) -1 || c == (gunichar) -2)
44
++    {
45
++      gchar *temp = g_strdup_printf ("\\x%02x", (guint)(guchar)*utf8);
46
++      memset (buf, 0, 8);
47
++      memcpy (buf, temp, strlen (temp));
48
++      g_free (temp);
49
++    }
50
++  else
51
++    char_str (c, buf);
52
+   return buf;
53
+ }
54
+ 
55
+diff --git a/glib/tests/Makefile.am b/glib/tests/Makefile.am
56
+index a690064..4c8028b 100644
57
+--- a/glib/tests/Makefile.am
58
+@@ -155,7 +155,8 @@ markup_tests = \
59
+ 	fail-31 fail-32 fail-33 fail-34 fail-35 \
60
+ 	fail-36 fail-37 fail-38 fail-39 fail-40 \
61
+ 	fail-41 fail-42 fail-43 fail-44 fail-45 \
62
+-	fail-46 fail-47 fail-48 fail-49 fail-51 \
63
++	fail-46 fail-47 fail-48 fail-49 fail-50 \
64
++	fail-51 \
65
+ 	valid-1 valid-2 valid-3 valid-4 valid-5 \
66
+ 	valid-6 valid-7 valid-8 valid-9 valid-10 \
67
+ 	valid-11 valid-12 valid-13 valid-14 valid-15 \
68
+diff --git a/glib/tests/markups/fail-50.expected b/glib/tests/markups/fail-50.expected
69
+new file mode 100644
70
+index 0000000..70d4498
71
+--- /dev/null
72
+@@ -0,0 +1 @@
73
++ERROR Error on line 1 char 5: Odd character '\xfc', expected an open quote mark after the equals sign when giving value for attribute 'r' of element ''
74
+diff --git a/glib/tests/markups/fail-50.gmarkup b/glib/tests/markups/fail-50.gmarkup
75
+new file mode 100644
76
+index 0000000..f110f15
77
+--- /dev/null
78
+@@ -0,0 +1 @@
79
++<	r=�
80
+\ No newline at end of file
81
+-- 
82
+2.7.4
... ...
@@ -1,7 +1,7 @@
1 1
 Summary:	Low-level libraries useful for providing data structure handling for C.
2 2
 Name:		glib
3 3
 Version:	2.52.1
4
-Release:	2%{?dist}
4
+Release:	3%{?dist}
5 5
 License:	LGPLv2+
6 6
 URL:		https://developer.gnome.org/glib/
7 7
 Group:		Applications/System
... ...
@@ -9,6 +9,8 @@ Vendor:		VMware, Inc.
9 9
 Distribution:	Photon
10 10
 Source0:	http://ftp.gnome.org/pub/gnome/sources/glib/2.52/%{name}-%{version}.tar.xz
11 11
 %define sha1 glib=ae55d5a476e7e9c08f06e22e9a723e4d0313a873
12
+Patch0:         glib-CVE-2018-16428.patch
13
+Patch1:         glib-CVE-2018-16429.patch
12 14
 BuildRequires:	pcre-devel
13 15
 BuildRequires:	libffi-devel
14 16
 BuildRequires:	pkg-config
... ...
@@ -48,6 +50,8 @@ Gsettings schemas compiling tool
48 48
 
49 49
 %prep
50 50
 %setup -q
51
+%patch0 -p1
52
+%patch1 -p1
51 53
 %build
52 54
 ./configure --prefix=/usr --with-pcre=system 
53 55
 make %{?_smp_mflags}
... ...
@@ -86,6 +90,8 @@ make DESTDIR=%{buildroot} install
86 86
 %{_datadir}/glib-2.0/schemas/*
87 87
 
88 88
 %changelog
89
+*   Fri Nov 02 2018 Keerthana K <keerthanak@vmware.com> 2.52.1-3
90
+-   Fix for CVE-2018-16428 and CVE-2018-16429.
89 91
 *   Fri Apr 14 2017 Alexey Makhalov <amakhalov@vmware.com> 2.52.1-2
90 92
 -   Requires pcre-libs, BuildRequires libffi-devel.
91 93
 *   Wed Apr 12 2017 Danut Moraru <dmoraru@vmware.com> 2.52.1-1