When formatting the error messages for markup parsing errors, the parser
was unconditionally reading a UTF-8 character from the input buffer —
but the buffer might end with a partial code sequence, resulting in
reading off the end of the buffer by up to three bytes.
Fix this and add a test case, courtesy of pdknsk.
Signed-off-by: Philip Withnall <withnall@endlessm.com>
https://gitlab.gnome.org/GNOME/glib/issues/1462
[Model] All
[BinType] AP
[Customer] OPEN
[Issue#] N/A
[Request] N/A
[Occurrence Version] N/A
[Problem] Security Patch
[Cause & Measure]
[Checking Method]
[Team] Open Source Management and Setting Part
[Developer] dh0128.kwak
[Solution company] Samsung
[Change Type] N/A
Change-Id: If7bc858e6de684d5a571b57bd2b3d2a8c48cfc63
Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
return buf;
}
+/* Format the next UTF-8 character as a gchar* for printing in error output
+ * when we encounter a syntax error. This correctly handles invalid UTF-8,
+ * emitting it as hex escapes. */
static gchar*
utf8_str (const gchar *utf8,
gchar *buf)
{
- char_str (g_utf8_get_char (utf8), buf);
+ gunichar c = g_utf8_get_char_validated (utf8, -1);
+ if (c == (gunichar) -1 || c == (gunichar) -2)
+ {
+ gchar *temp = g_strdup_printf ("\\x%02x", (guint)(guchar)*utf8);
+ memset (buf, 0, 8);
+ memcpy (buf, temp, strlen (temp));
+ g_free (temp);
+ }
+ else
+ char_str (c, buf);
return buf;
}