From b0b16cf06e646786968255b0fcaf77aa21b5f9bb Mon Sep 17 00:00:00 2001 From: Luca Bacci Date: Wed, 21 Dec 2022 13:57:29 +0100 Subject: [PATCH 1/2] GWin32AppInfo: Check for local file path first When launching a registered handler we compose the command-line string using the registered command-line template. Applications expect files in their command-line as local paths rather than complete URI strings. For example, "Program.exe" "%1" Should expand to "Program.exe" "C:\file.dat" Rather than "Program.exe" "file:///C:\file.dat" Fixes https://gitlab.gnome.org/GNOME/glib/-/issues/2843 --- gio/gwin32appinfo.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/gio/gwin32appinfo.c b/gio/gwin32appinfo.c index dec82954f..5ed39837b 100644 --- a/gio/gwin32appinfo.c +++ b/gio/gwin32appinfo.c @@ -4334,10 +4334,25 @@ expand_macro_single (char macro, file_or_uri *obj) case '8': case '9': /* TODO: handle 'l' and 'd' differently (longname and desktop name) */ - if (obj->uri) - result = g_strdup (obj->uri); - else if (obj->file) - result = g_strdup (obj->file); + if (obj->file) + { + result = g_strdup (obj->file); + } + else if (obj->uri) + { + const char *prefix = "file:///"; + const size_t prefix_len = strlen (prefix); + + if (g_str_has_prefix (obj->uri, prefix) == 0 && obj->uri[prefix_len] != 0) + { + GFile *file = g_file_new_for_uri (obj->uri); + result = g_file_get_path (file); + g_object_unref (file); + } + + if (!result) + result = g_strdup (obj->uri); + } break; case 'u': case 'U': From 3c2b15fb155459369885fa6f6e6a4f5e98b42b66 Mon Sep 17 00:00:00 2001 From: Luca Bacci Date: Wed, 21 Dec 2022 15:01:45 +0100 Subject: [PATCH 2/2] GWin32AppInfo: Fix use-after-free --- gio/gwin32appinfo.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gio/gwin32appinfo.c b/gio/gwin32appinfo.c index 5ed39837b..0a6f8ae29 100644 --- a/gio/gwin32appinfo.c +++ b/gio/gwin32appinfo.c @@ -5298,14 +5298,18 @@ make_item_array (gboolean for_files, } hr = SHParseDisplayName (file_or_uri_utf16, NULL, &item_ids[i], 0, NULL); - g_free (file_or_uri_utf16); if (FAILED (hr)) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "File or URI `%S' cannot be parsed by SHParseDisplayName: 0x%lx", file_or_uri_utf16, hr); + "File or URI `%S' cannot be parsed by SHParseDisplayName: 0x%lx", + file_or_uri_utf16, hr); + + g_free (file_or_uri_utf16); break; } + + g_free (file_or_uri_utf16); } if (i == count)