diff options
author | Rui Matos <tiagomatos@gmail.com> | 2016-06-07 16:11:05 +0200 |
---|---|---|
committer | Rui Matos <tiagomatos@gmail.com> | 2016-06-07 20:17:37 +0200 |
commit | 8f7a36c53f59b34e96580d73733679951ec0b6a1 (patch) | |
tree | 066cfc578816b6f05bcc6dc422939d4f355084dd /src/core | |
parent | 8d7ae5256553a06347a41b765c8f55df37dbeccb (diff) | |
download | mutter-8f7a36c53f59b34e96580d73733679951ec0b6a1.tar.gz |
window: Don't create invalid UTF-8 window description strings
printf string precision counts bytes so we may end up creating invalid
UTF-8 strings here. Instead, use glib's unicode aware methods to clip
the title.
https://bugzilla.gnome.org/show_bug.cgi?id=765535
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/window.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/core/window.c b/src/core/window.c index 462fd412c..4dff32b2a 100644 --- a/src/core/window.c +++ b/src/core/window.c @@ -761,12 +761,18 @@ sync_client_window_mapped (MetaWindow *window) static void meta_window_update_desc (MetaWindow *window) { + g_autofree gchar *title = NULL; + g_clear_pointer (&window->desc, g_free); + if (window->title) + title = g_utf8_substring (window->title, 0, + MIN (10, g_utf8_strlen (window->title, -1))); + if (window->client_type == META_WINDOW_CLIENT_TYPE_X11) { - if (window->title) - window->desc = g_strdup_printf ("0x%lx (%.10s)", window->xwindow, window->title); + if (title) + window->desc = g_strdup_printf ("0x%lx (%s)", window->xwindow, title); else window->desc = g_strdup_printf ("0x%lx", window->xwindow); } @@ -774,8 +780,8 @@ meta_window_update_desc (MetaWindow *window) { guint64 small_stamp = window->stamp - G_GUINT64_CONSTANT(0x100000000); - if (window->title) - window->desc = g_strdup_printf ("W%" G_GUINT64_FORMAT " (%.10s)", small_stamp, window->title); + if (title) + window->desc = g_strdup_printf ("W%" G_GUINT64_FORMAT " (%s)", small_stamp, title); else window->desc = g_strdup_printf ("W%" G_GUINT64_FORMAT , small_stamp); } |