all repos — openbox @ f68eb1fc250b13a473d825ac5c69b6d5e28b9595

openbox fork - make it a bit more like ryudo

validate utf8 strings before using them
Dana Jansens danakj@orodu.net
commit

f68eb1fc250b13a473d825ac5c69b6d5e28b9595

parent

b46222c3d9b4b638b14647871d41249db9726422

1 files changed, 11 insertions(+), 3 deletions(-)

jump to
M openbox/prop.copenbox/prop.c

@@ -306,12 +306,17 @@

gboolean prop_get_string_utf8(Window win, Atom prop, char **ret) { char *raw; + char *str; guint num; if (get_all(win, prop, prop_atoms.utf8, 8, (guchar**)&raw, &num)) { - *ret = g_strndup(raw, num); /* grab the first string from the list */ + str = g_strndup(raw, num); /* grab the first string from the list */ g_free(raw); - return TRUE; + if (g_utf8_validate(str, -1, NULL)) { + *ret = str; + return TRUE; + } + g_free(str); } return FALSE; }

@@ -327,7 +332,10 @@ (*ret)[num] = NULL; /* null terminated list */

p = raw; for (i = 0; i < num; ++i) { - (*ret)[i] = g_strdup(p); + if (g_utf8_validate(p, -1, NULL)) + (*ret)[i] = g_strdup(p); + else + (*ret)[i] = g_strdup(""); p += strlen(p) + 1; } g_free(raw);