From acc9d59e97307e654c55231910194bc76393b9df Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Fri, 28 May 2010 12:08:39 +0200 Subject: [PATCH] Bugfix: Correctly check asprintf() return value Fixes a crash when invalid multibyte window titles are set as _NET_WM_NAME --- src/handlers.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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.