]> git.sur5r.net Git - i3/i3/commitdiff
Truncate wm_name utf8 strings to first zero byte
authorOrestis Floros <orestisf1993@gmail.com>
Fri, 9 Nov 2018 17:41:31 +0000 (19:41 +0200)
committerMichael Stapelberg <michael@stapelberg.de>
Wed, 23 Jan 2019 20:20:00 +0000 (21:20 +0100)
Fixes #3515

src/window.c

index 68c6933a4c2eb4c51a7c2d91b42d0c89f38340d4..6128255686942f80b74f491a22fb296ef1d47da6 100644 (file)
@@ -74,8 +74,12 @@ void window_update_name(i3Window *win, xcb_get_property_reply_t *prop, bool befo
     }
 
     i3string_free(win->name);
     }
 
     i3string_free(win->name);
-    win->name = i3string_from_utf8_with_length(xcb_get_property_value(prop),
-                                               xcb_get_property_value_length(prop));
+
+    /* Truncate the name at the first zero byte. See #3515. */
+    const int len = xcb_get_property_value_length(prop);
+    char *name = sstrndup(xcb_get_property_value(prop), len);
+    win->name = i3string_from_utf8(name);
+    free(name);
 
     Con *con = con_by_window_id(win->id);
     if (con != NULL && con->title_format != NULL) {
 
     Con *con = con_by_window_id(win->id);
     if (con != NULL && con->title_format != NULL) {
@@ -119,8 +123,10 @@ void window_update_name_legacy(i3Window *win, xcb_get_property_reply_t *prop, bo
     }
 
     i3string_free(win->name);
     }
 
     i3string_free(win->name);
-    win->name = i3string_from_utf8_with_length(xcb_get_property_value(prop),
-                                               xcb_get_property_value_length(prop));
+    const int len = xcb_get_property_value_length(prop);
+    char *name = sstrndup(xcb_get_property_value(prop), len);
+    win->name = i3string_from_utf8(name);
+    free(name);
 
     Con *con = con_by_window_id(win->id);
     if (con != NULL && con->title_format != NULL) {
 
     Con *con = con_by_window_id(win->id);
     if (con != NULL && con->title_format != NULL) {