GDesktopAppInfo: support bus activation with '-'

GApplication has accepted any valid bus name as an application ID since
before the time of D-Bus activation.  This includes bus names with '-'.
Several applications have even attempted support bus activation with
these names, going as far as installing D-Bus service files, without
realising that they are silently falling back to fork()/exec() on
account of the name containing a dash.

The reason for the problem is that D-Bus object paths cannot contain
dashes.  We solved this problem privately in an unspecified way inside
of GApplication but substituting '_' in this case, but never made this
part of the Desktop Entry Specification.

The fact that these apps with '-' in the desktop file names aren't
actually using D-Bus activation is beside the point: their intent here
was clear.  Let's avoid forcing them to rename their desktop files again
by simply accepting '-' in desktop file names and munging the path in
the way that GApplication did so historically.

The new path escaping code here has been copied more or less verbatim
from GApplication's own code for the same purpose, with only the removal
of one irrelevant part.

An update to the desktop entry specification will follow.

https://bugzilla.gnome.org/show_bug.cgi?id=764754
This commit is contained in:
Allison Ryan Lortie 2016-04-12 11:06:11 -04:00
parent bd0911afda
commit 3301b852a2

View File

@ -1794,7 +1794,7 @@ g_desktop_app_info_load_from_keyfile (GDesktopAppInfo *info,
{
*last_dot = '\0';
if (g_dbus_is_interface_name (basename))
if (g_dbus_is_name (basename) && basename[0] != ':')
info->app_id = g_strdup (basename);
}
@ -2785,25 +2785,21 @@ g_desktop_app_info_launch_uris_with_spawn (GDesktopAppInfo *info,
}
static gchar *
object_path_from_appid (const gchar *app_id)
object_path_from_appid (const gchar *appid)
{
gchar *path;
gint i, n;
gchar *appid_path, *iter;
n = strlen (app_id);
path = g_malloc (n + 2);
appid_path = g_strconcat ("/", appid, NULL);
for (iter = appid_path; *iter; iter++)
{
if (*iter == '.')
*iter = '/';
path[0] = '/';
if (*iter == '-')
*iter = '_';
}
for (i = 0; i < n; i++)
if (app_id[i] != '.')
path[i + 1] = app_id[i];
else
path[i + 1] = '/';
path[i + 1] = '\0';
return path;
return appid_path;
}
static GVariant *