From 41fc0955f6f987e59396aa11b7bbfbb43e39eb94 Mon Sep 17 00:00:00 2001 From: Arjan Molenaar Date: Sat, 8 Jul 2023 14:28:57 +0200 Subject: [PATCH 1/3] Add additional check for NULL text Although text should be a string, it is possible that (e.g via language bindings) a NULL text is entered. When this happens, the app just crashes. This changes adds a not-NULL check for text input to ensure that whatever is provided is valid. --- gtk/gtkeditable.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gtk/gtkeditable.c b/gtk/gtkeditable.c index 242a5c8d8a..1324256237 100644 --- a/gtk/gtkeditable.c +++ b/gtk/gtkeditable.c @@ -482,6 +482,7 @@ gtk_editable_insert_text (GtkEditable *editable, int *position) { g_return_if_fail (GTK_IS_EDITABLE (editable)); + g_return_if_fail (text != NULL); g_return_if_fail (position != NULL); if (length < 0) @@ -594,6 +595,7 @@ gtk_editable_set_text (GtkEditable *editable, int pos; g_return_if_fail (GTK_IS_EDITABLE (editable)); + g_return_if_fail (text != NULL); g_object_freeze_notify (G_OBJECT (editable)); gtk_editable_delete_text (editable, 0, -1); From 1e5a9eb7b9e0a74753d3cb2397610c4345467fbe Mon Sep 17 00:00:00 2001 From: Arjan Molenaar Date: Sat, 16 Sep 2023 20:50:23 +0200 Subject: [PATCH 2/3] Be lenient with input text Allow text to be NULL, but treat it as an empty string in order to avoid segfaults. Use the same method already used by GtkLabel to avoid NULL being used as text. --- gtk/gtkeditable.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gtk/gtkeditable.c b/gtk/gtkeditable.c index 1324256237..e112a55622 100644 --- a/gtk/gtkeditable.c +++ b/gtk/gtkeditable.c @@ -482,9 +482,11 @@ gtk_editable_insert_text (GtkEditable *editable, int *position) { g_return_if_fail (GTK_IS_EDITABLE (editable)); - g_return_if_fail (text != NULL); g_return_if_fail (position != NULL); + if (text == NULL) + text = ""; + if (length < 0) length = strlen (text); @@ -595,7 +597,6 @@ gtk_editable_set_text (GtkEditable *editable, int pos; g_return_if_fail (GTK_IS_EDITABLE (editable)); - g_return_if_fail (text != NULL); g_object_freeze_notify (G_OBJECT (editable)); gtk_editable_delete_text (editable, 0, -1); From 1237fd9ab55991b4342f6b632ccc24feea256071 Mon Sep 17 00:00:00 2001 From: Arjan Molenaar Date: Sat, 13 Jan 2024 21:42:19 +0100 Subject: [PATCH 3/3] Add non-NULL check for gtk_editable_set_text() --- gtk/gtkeditable.c | 1 + 1 file changed, 1 insertion(+) diff --git a/gtk/gtkeditable.c b/gtk/gtkeditable.c index e112a55622..7e135fa004 100644 --- a/gtk/gtkeditable.c +++ b/gtk/gtkeditable.c @@ -597,6 +597,7 @@ gtk_editable_set_text (GtkEditable *editable, int pos; g_return_if_fail (GTK_IS_EDITABLE (editable)); + g_return_if_fail (text != NULL); g_object_freeze_notify (G_OBJECT (editable)); gtk_editable_delete_text (editable, 0, -1);