mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 11:26:16 +01:00
gdesktopappinfo: Gracefully handle NULL URIs when passed to expand_macro()
If an application calls g_app_info_launch_uris() with a GList that includes NULL values in some of its data members, and GIO ends up internally calling g_desktop_app_info_launch_uris_with_spawn() for whatever reason (e.g. no D-Bus session available), expand_macro() will crash due to the invalid data. As this is considered a programmer error, use g_return_val_if_fail() in those situations to prevent the crash from happening, but printing a warning anyway. https://bugzilla.gnome.org/show_bug.cgi?id=791337
This commit is contained in:
parent
fbed9c8b85
commit
d501bd0dbe
@ -2199,7 +2199,7 @@ g_desktop_app_info_get_show_in (GDesktopAppInfo *info,
|
|||||||
/* Launching... {{{2 */
|
/* Launching... {{{2 */
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
expand_macro_single (char macro, char *uri)
|
expand_macro_single (char macro, const char *uri)
|
||||||
{
|
{
|
||||||
GFile *file;
|
GFile *file;
|
||||||
char *result = NULL;
|
char *result = NULL;
|
||||||
@ -2248,6 +2248,29 @@ expand_macro_single (char macro, char *uri)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char *
|
||||||
|
expand_macro_uri (char macro, const char *uri, gboolean force_file_uri, char force_file_uri_macro)
|
||||||
|
{
|
||||||
|
char *expanded = NULL;
|
||||||
|
|
||||||
|
g_return_val_if_fail (uri != NULL, NULL);
|
||||||
|
|
||||||
|
if (!force_file_uri ||
|
||||||
|
/* Pass URI if it contains an anchor */
|
||||||
|
strchr (uri, '#') != NULL)
|
||||||
|
{
|
||||||
|
expanded = expand_macro_single (macro, uri);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
expanded = expand_macro_single (force_file_uri_macro, uri);
|
||||||
|
if (expanded == NULL)
|
||||||
|
expanded = expand_macro_single (macro, uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
return expanded;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
expand_macro (char macro,
|
expand_macro (char macro,
|
||||||
GString *exec,
|
GString *exec,
|
||||||
@ -2255,10 +2278,10 @@ expand_macro (char macro,
|
|||||||
GList **uri_list)
|
GList **uri_list)
|
||||||
{
|
{
|
||||||
GList *uris = *uri_list;
|
GList *uris = *uri_list;
|
||||||
char *expanded;
|
char *expanded = NULL;
|
||||||
gboolean force_file_uri;
|
gboolean force_file_uri;
|
||||||
char force_file_uri_macro;
|
char force_file_uri_macro;
|
||||||
char *uri;
|
const char *uri;
|
||||||
|
|
||||||
g_return_if_fail (exec != NULL);
|
g_return_if_fail (exec != NULL);
|
||||||
|
|
||||||
@ -2295,19 +2318,8 @@ expand_macro (char macro,
|
|||||||
if (uris)
|
if (uris)
|
||||||
{
|
{
|
||||||
uri = uris->data;
|
uri = uris->data;
|
||||||
if (!force_file_uri ||
|
expanded = expand_macro_uri (macro, uri,
|
||||||
/* Pass URI if it contains an anchor */
|
force_file_uri, force_file_uri_macro);
|
||||||
strchr (uri, '#') != NULL)
|
|
||||||
{
|
|
||||||
expanded = expand_macro_single (macro, uri);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
expanded = expand_macro_single (force_file_uri_macro, uri);
|
|
||||||
if (expanded == NULL)
|
|
||||||
expanded = expand_macro_single (macro, uri);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (expanded)
|
if (expanded)
|
||||||
{
|
{
|
||||||
g_string_append (exec, expanded);
|
g_string_append (exec, expanded);
|
||||||
@ -2325,20 +2337,8 @@ expand_macro (char macro,
|
|||||||
while (uris)
|
while (uris)
|
||||||
{
|
{
|
||||||
uri = uris->data;
|
uri = uris->data;
|
||||||
|
expanded = expand_macro_uri (macro, uri,
|
||||||
if (!force_file_uri ||
|
force_file_uri, force_file_uri_macro);
|
||||||
/* Pass URI if it contains an anchor */
|
|
||||||
strchr (uri, '#') != NULL)
|
|
||||||
{
|
|
||||||
expanded = expand_macro_single (macro, uri);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
expanded = expand_macro_single (force_file_uri_macro, uri);
|
|
||||||
if (expanded == NULL)
|
|
||||||
expanded = expand_macro_single (macro, uri);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (expanded)
|
if (expanded)
|
||||||
{
|
{
|
||||||
g_string_append (exec, expanded);
|
g_string_append (exec, expanded);
|
||||||
|
Loading…
Reference in New Issue
Block a user