[neon/backports-focal/xdg-desktop-portal/Neon/unstable] src: open-uri: Don't crash if there is no default or latest app

Simon McVittie null at kde.org
Wed Jan 13 06:32:43 GMT 2021


Git commit 406a8849261e6301a66b7f1ece35051afd828592 by Simon McVittie.
Committed on 07/09/2020 at 13:20.
Pushed by ash into branch 'Neon/unstable'.

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 at collabora.com>

M  +5    -3    src/open-uri.c

https://invent.kde.org/neon/backports-focal/xdg-desktop-portal/commit/406a8849261e6301a66b7f1ece35051afd828592

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)



More information about the Neon-commits mailing list