xdg-desktop-portal-gtk/SOURCES/0001-appchooserdialog-avoid...

39 lines
1.2 KiB
Diff

From 54ceb35d892ac33c59f4d255359d8184f1b72679 Mon Sep 17 00:00:00 2001
From: Michael Catanzaro <mcatanzaro@gnome.org>
Date: Fri, 1 May 2020 17:58:35 -0500
Subject: [PATCH 1/4] appchooserdialog: avoid crash when there are few app
options
Problem is the code reads off the end of the choices list when the
number of choices is less than INITIAL_LIST_SIZE - 1.
Fixes #302
(cherry picked from commit 7d2b3e270b6a964d8007b5cbb5dfc52c3f9a23ce)
---
src/appchooserdialog.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/appchooserdialog.c b/src/appchooserdialog.c
index 82e362e..0b9f31e 100644
--- a/src/appchooserdialog.c
+++ b/src/appchooserdialog.c
@@ -384,11 +384,11 @@ app_chooser_dialog_new (const char **choices,
gtk_label_set_label (GTK_LABEL (dialog->heading), _("Choose an application."));
}
- ensure_default_is_below (choices, default_id, INITIAL_LIST_SIZE - 1);
-
dialog->choices = g_strdupv ((char **)choices);
-
n_choices = g_strv_length ((char **)choices);
+
+ ensure_default_is_below (dialog->choices, default_id, MIN (n_choices, INITIAL_LIST_SIZE - 1));
+
if (n_choices == 0)
{
gtk_widget_show (dialog->empty_box);
--
2.26.2