From: Michael Stapelberg Date: Fri, 28 May 2010 10:08:39 +0000 (+0200) Subject: Bugfix: Correctly check asprintf() return value X-Git-Tag: 4.0~70 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=169e541101777fd3a3cd32f0adb6b6329d5ba6d7;p=i3%2Fi3 Bugfix: Correctly check asprintf() return value Fixes a crash when invalid multibyte window titles are set as _NET_WM_NAME --- diff --git a/src/handlers.c b/src/handlers.c index a173777c..12e81f71 100644 --- a/src/handlers.c +++ b/src/handlers.c @@ -613,11 +613,19 @@ int handle_windowname_change(void *data, xcb_connection_t *conn, uint8_t state, /* Save the old pointer to make the update atomic */ char *new_name; int new_len; - asprintf(&new_name, "%.*s", xcb_get_property_value_length(prop), (char*)xcb_get_property_value(prop)); + if (asprintf(&new_name, "%.*s", xcb_get_property_value_length(prop), (char*)xcb_get_property_value(prop)) == -1) { + perror("asprintf"); + LOG("Could not format _NET_WM_NAME, ignoring new hint\n"); + return 1; + } /* Convert it to UCS-2 here for not having to convert it later every time we want to pass it to X */ char *ucs2_name = convert_utf8_to_ucs2(new_name, &new_len); LOG("_NET_WM_NAME changed to \"%s\"\n", new_name); free(new_name); + if (ucs2_name == NULL) { + LOG("Could not convert _NET_WM_NAME to UCS-2, ignoring new hint\n"); + return 1; + } /* Check if they are the same and don’t update if so. Note the use of new_len * 2 to check all bytes as each glyph takes 2 bytes.