From ffce7d8e70f357150256e5074732cf6594b8fc74 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Tue, 24 Nov 2020 20:37:47 +0000 Subject: [PATCH] Cope with a GdkEventKey having a NULL string field. When you run using the GDK Broadway backend, this turns out to happen, and it's new in my experience - I was cheerfully iterating over event->string and calling strlen on it without ever checking it for NULL. --- unix/gtkwin.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/unix/gtkwin.c b/unix/gtkwin.c index 033af077..18dfd39d 100644 --- a/unix/gtkwin.c +++ b/unix/gtkwin.c @@ -1035,6 +1035,7 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data) bool force_format_numeric_keypad = false; bool generated_something = false; char num_keypad_key = '\0'; + const char *event_string = event->string ? event->string : ""; noise_ultralight(NOISE_SOURCE_KEY, event->keyval); @@ -1106,11 +1107,11 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data) string_string = dupstr(""); { int i; - for (i = 0; event->string[i]; i++) { + for (i = 0; event_string[i]; i++) { char *old = string_string; string_string = dupprintf("%s%s%02x", string_string, string_string[0] ? " " : "", - (unsigned)event->string[i] & 0xFF); + (unsigned)event_string[i] & 0xFF); sfree(old); } } @@ -1443,7 +1444,7 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data) * confirmation.) */ output_charset = CS_ISO8859_1; - strncpy(output+1, event->string, lenof(output)-1); + strncpy(output+1, event_string, lenof(output)-1); #else /* !GTK_CHECK_VERSION(2,0,0) */ /* * Most things can now be passed to @@ -1552,7 +1553,7 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data) int ulen; wlen = mb_to_wc(DEFAULT_CODEPAGE, 0, - event->string, strlen(event->string), + event_string, strlen(event_string), widedata, lenof(widedata)-1); #ifdef KEY_EVENT_DIAGNOSTICS