xdg-desktop-portal/SOURCES/xdg-desktop-portal-1.6.0-fi...

54 lines
1.8 KiB
Diff

From 406a8849261e6301a66b7f1ece35051afd828592 Mon Sep 17 00:00:00 2001
From: Simon McVittie <smcv@collabora.com>
Date: Sun, 6 Sep 2020 15:32:14 +0100
Subject: [PATCH] open-uri: Don't crash if there is no default or latest app
g_desktop_app_info_new() requires a non-NULL argument.
Partially addresses #524.
Fixes: 69205f12 "open-uri: Show app chooser when default app does not exist"
Signed-off-by: Simon McVittie <smcv@collabora.com>
---
src/open-uri.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/src/open-uri.c b/src/open-uri.c
index bb63478..f746e64 100644
--- a/src/open-uri.c
+++ b/src/open-uri.c
@@ -555,6 +555,8 @@ app_exists (const char *app_id)
{
g_autoptr(GDesktopAppInfo) info = NULL;
+ g_return_val_if_fail (app_id != NULL, FALSE);
+
info = g_desktop_app_info_new (app_id);
return (info != NULL);
}
@@ -667,13 +669,13 @@ handle_open_in_thread_func (GTask *task,
/* collect all the information */
find_recommended_choices (scheme, content_type, &default_app, &choices, &n_choices);
- if (!app_exists (default_app))
+ if (default_app != NULL && !app_exists (default_app))
g_clear_pointer (&default_app, g_free);
use_default_app = should_use_default_app (scheme, content_type);
get_latest_choice_info (app_id, content_type,
&latest_id, &latest_count, &latest_threshold,
&ask_for_content_type);
- if (!app_exists (latest_id))
+ if (latest_id != NULL && !app_exists (latest_id))
g_clear_pointer (&latest_id, g_free);
skip_app_chooser = FALSE;
@@ -729,7 +731,7 @@ handle_open_in_thread_func (GTask *task,
app = latest_id;
else if (default_app != NULL)
app = default_app;
- else if (choices && app_exists (choices[0]))
+ else if (n_choices > 0 && app_exists (choices[0]))
app = choices[0];
if (app)