After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 738690 - gvfs-open: Fix incorrect use of g_app_info_launch_default_for_uri()
gvfs-open: Fix incorrect use of g_app_info_launch_default_for_uri()
Status: RESOLVED FIXED
Product: gvfs
Classification: Core
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: gvfs-maint
gvfs-maint
: 748600 748912 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2014-10-17 13:57 UTC by Bastien Nocera
Modified: 2017-10-26 06:41 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gvfs-open: Fix incorrect use of g_app_info_launch_default_for_uri() (1.61 KB, patch)
2014-10-17 13:57 UTC, Bastien Nocera
committed Details | Review
client: Do not create GDaemonFile for unknown schemes (1.53 KB, patch)
2015-04-29 12:55 UTC, Ondrej Holy
none Details | Review
gvfs-open: Do not alter uris before use (1.95 KB, patch)
2015-05-19 11:20 UTC, Ondrej Holy
none Details | Review
gvfs-open: Do not alter uris before use (1.94 KB, patch)
2015-05-20 15:49 UTC, Ondrej Holy
committed Details | Review

Description Bastien Nocera 2014-10-17 13:57:01 UTC
.
Comment 1 Bastien Nocera 2014-10-17 13:57:04 UTC
Created attachment 288754 [details] [review]
gvfs-open: Fix incorrect use of g_app_info_launch_default_for_uri()

First, as we never check whether the passed arguments are indeed URIs,
we'd be failing to work correctly for relative paths.
Secondly, we would be running g_app_info_launch_default_for_uri() twice
for no good reason.
Finally, we were leaking the output of g_file_get_uri()
Comment 2 Ross Lagerwall 2014-10-17 20:08:11 UTC
Review of attachment 288754 [details] [review]:

It introduces a warning:
make[2]: Entering directory '/home/ross/src/gnome/gvfs/programs'
  CC       gvfs-open.o
gvfs-open.c: In function ‘main’:
gvfs-open.c:53:10: warning: unused variable ‘file’ [-Wunused-variable]
   GFile *file;
          ^
  CCLD     gvfs-open


Otherwise looks good.
Comment 3 Bastien Nocera 2015-01-28 13:29:34 UTC
With the unused variable removed.

Attachment 288754 [details] pushed as 95aac17 - gvfs-open: Fix incorrect use of g_app_info_launch_default_for_uri()
Comment 4 Ondrej Holy 2015-04-29 10:03:41 UTC
The patch broke the gvfs-open for schemes i.e. mailto, magnet, irc. We should support such uris, while gvfs-open is called from xdg-open.

See Bug 748600 for more details. So the patch should be reverted, leak fixed separately and comment added to explain why we call g_app_info_launch_default_for_uri twice...
Comment 5 Bastien Nocera 2015-04-29 10:07:24 UTC
(In reply to Ondrej Holy from comment #4)
> The patch broke the gvfs-open for schemes i.e. mailto, magnet, irc. We
> should support such uris, while gvfs-open is called from xdg-open.
> 
> See Bug 748600 for more details. So the patch should be reverted, leak fixed
> separately and comment added to explain why we call
> g_app_info_launch_default_for_uri twice...

I already said so in bug 748600, the patch is not broken. g_app_info_launch_default_for_uri() is for those URIs.
Comment 6 Ondrej Holy 2015-04-29 10:46:46 UTC
Sorry I missed the comment in Bug 748600.

But the problem is that we "preprocess" the uri using g_file_get_uri (g_file_new_for_commandline_arg (location)), which e.g. for mailto:address returns mailto:///address...

g_app_info_launch_default_for_uri() opens correct application, but with wrong uri...
Comment 7 Bastien Nocera 2015-04-29 10:54:06 UTC
(In reply to Ondrej Holy from comment #6)
> Sorry I missed the comment in Bug 748600.
> 
> But the problem is that we "preprocess" the uri using g_file_get_uri
> (g_file_new_for_commandline_arg (location)), which e.g. for mailto:address
> returns mailto:///address...

mailto:address to mailto:///address looks very wrong.

It shouldn't mangle the URI for schemes it cannot express in GFile.

> g_app_info_launch_default_for_uri() opens correct application, but with
> wrong uri...
Comment 8 Ondrej Holy 2015-04-29 12:55:15 UTC
Created attachment 302563 [details] [review]
client: Do not create GDaemonFile for unknown schemes

It is because new GDaemonFile is created and the uri is constructed from mountspec (see g_daemon_vfs_get_file_for_uri, g_daemon_file_get_uri). I'm not sure why we are creating new GDaemonFile for schemes, which we can't handle. Probably we should call g_local_vfs_get_file_for_uri instead and let them create GDummyFile. But not sure we don't brake anything with this change...
Comment 9 Ondrej Holy 2015-05-05 07:26:57 UTC
(In reply to Bastien Nocera from comment #7)
> (In reply to Ondrej Holy from comment #6)
> > Sorry I missed the comment in Bug 748600.
> > 
> > But the problem is that we "preprocess" the uri using g_file_get_uri
> > (g_file_new_for_commandline_arg (location)), which e.g. for mailto:address
> > returns mailto:///address...
> 
> mailto:address to mailto:///address looks very wrong.
> 
> It shouldn't mangle the URI for schemes it cannot express in GFile.

See Bug 748912, there could be also problem with altering uris which we can express using GFile...

"ssh://user@host" becomes "ssh://user@host/"

...but it is true that the original uri is probably invalid according RFC, isn't it? Anyway it isn't good idea to modify the uri if it won't be used in GVfs...
Comment 10 Ondrej Holy 2015-05-19 11:20:06 UTC
Created attachment 303585 [details] [review]
gvfs-open: Do not alter uris before use

Uri is altered before g_app_info_launch_default_for_uri, because of the following code (from the commit 95aac17):

file = g_file_new_for_commandline_arg (location[i])
uri = g_file_get_uri (file);

Examples of uri changes:

mailto:email -> mailto:///email
ssh://user@host -> sftp://user@host/

This patch cause that uri isn't preprocessed for locations with scheme (however absolute and relative paths are still preprocessed).
Comment 11 Ondrej Holy 2015-05-19 11:21:38 UTC
*** Bug 748912 has been marked as a duplicate of this bug. ***
Comment 12 Ondrej Holy 2015-05-19 11:21:52 UTC
*** Bug 748600 has been marked as a duplicate of this bug. ***
Comment 13 Bastien Nocera 2015-05-19 11:27:02 UTC
Review of attachment 303585 [details] [review]:

::: programs/gvfs-open.c
@@ -107,3 @@
-      char *uri;
-
-      file = g_file_new_for_commandline_arg (locations[i]);

Here, check the output of g_file_get_uri_scheme() as you do in your patch.

@@ +111,3 @@
+       * we don't want. See:
+       * https://bugzilla.gnome.org/show_bug.cgi?id=738690 */
+      uri_scheme = g_uri_parse_scheme (locations[i]);

We shouldn't do that, the local path passed might "look like" a URI.

@@ +120,3 @@
+          g_object_unref (file);
+
+          g_free (usi_scheme);

I doubt that it was even compile-tested.
Comment 14 Ondrej Holy 2015-05-19 12:04:37 UTC
(In reply to Bastien Nocera from comment #13)
> Review of attachment 303585 [details] [review] [review]:
> 
> ::: programs/gvfs-open.c
> @@ -107,3 @@
> -      char *uri;
> -
> -      file = g_file_new_for_commandline_arg (locations[i]);
> 
> Here, check the output of g_file_get_uri_scheme() as you do in your patch.

As far as I know g_file_get_uri_scheme(g_file_new_for_commandline_arg()) never return NULL or empty scheme... So should I use g_file_get_uri() only if "file" scheme is returned, or what to do with?

> @@ +111,3 @@
> +       * we don't want. See:
> +       * https://bugzilla.gnome.org/show_bug.cgi?id=738690 */
> +      uri_scheme = g_uri_parse_scheme (locations[i]);
> 
> We shouldn't do that, the local path passed might "look like" a URI.

Do you think files with name e.g. "mailto:myfile"? Ok, this won't work, but it doesn't work correctly neither with g_file_new_for_commandline_arg() and g_file_get_uri_scheme returns "mailto"...

> @@ +120,3 @@
> +          g_object_unref (file);
> +
> +          g_free (usi_scheme);
> 
> I doubt that it was even compile-tested.

I am sorry, I forgot recreated patch after amending...
Comment 15 Ondrej Holy 2015-05-20 15:15:02 UTC
(In reply to Ondrej Holy from comment #14)
> (In reply to Bastien Nocera from comment #13)
> > Review of attachment 303585 [details] [review] [review] [review]:
> > @@ +111,3 @@
> > +       * we don't want. See:
> > +       * https://bugzilla.gnome.org/show_bug.cgi?id=738690 */
> > +      uri_scheme = g_uri_parse_scheme (locations[i]);
> > 
> > We shouldn't do that, the local path passed might "look like" a URI.
> 
> Do you think files with name e.g. "mailto:myfile"? Ok, this won't work, but
> it doesn't work correctly neither with g_file_new_for_commandline_arg() and
> g_file_get_uri_scheme returns "mailto"...

But hard to say what is correct, if you call e.g.:
gvfs-open mailto\:myfile

It can be handled like uri, or it can be handled like relative path. g_file_new_for_commandline_arg handles this like an uri, same as the proposed patch. So I think the patch is correct, or do you have in mind something else?
Comment 16 Bastien Nocera 2015-05-20 15:22:38 UTC
Fine by me then...
Comment 17 Ondrej Holy 2015-05-20 15:49:58 UTC
Created attachment 303678 [details] [review]
gvfs-open: Do not alter uris before use

Ok, so there is amended version...
Comment 18 Ross Lagerwall 2015-05-25 13:28:50 UTC
Review of attachment 303678 [details] [review]:

Seems ok.
Comment 19 Ondrej Holy 2015-05-25 13:45:30 UTC
Comment on attachment 303678 [details] [review]
gvfs-open: Do not alter uris before use

Thanks for the review!

Pushed to master as:
commit dd650d4a82ee369df960bc8e40024e75cad0ba88

and gnome-3-16 as:
commit 98c3b3ce6f1261d3198a07b7f90644d6cb417556
Comment 20 Ondrej Holy 2017-10-26 06:41:59 UTC
*** Bug 748912 has been marked as a duplicate of this bug. ***