@@ -878,6 +878,32 @@ read_fd (int fd,
878
878
return TRUE;
879
879
}
880
880
881
+ /* This is conservative, but lets us avoid escaping most
882
+ regular Exec= lines, which is nice as that can sometimes
883
+ cause problems for apps launching desktop files. */
884
+ static gboolean
885
+ need_quotes (const char * str )
886
+ {
887
+ const char * p ;
888
+
889
+ for (p = str ; * p ; p ++ )
890
+ {
891
+ if (!g_ascii_isalnum (* p ) &&
892
+ strchr ("-_%.=:/@" , * p ) == NULL )
893
+ return TRUE;
894
+ }
895
+
896
+ return FALSE;
897
+ }
898
+
899
+ static char *
900
+ maybe_quote (const char * str )
901
+ {
902
+ if (need_quotes (str ))
903
+ return g_shell_quote (str );
904
+ return g_strdup (str );
905
+ }
906
+
881
907
static gboolean
882
908
export_desktop_file (const char * app ,
883
909
const char * branch ,
@@ -903,7 +929,9 @@ export_desktop_file (const char *app,
903
929
glnx_strfreev gchar * * old_argv = NULL ;
904
930
glnx_strfreev gchar * * groups = NULL ;
905
931
GString * new_exec = NULL ;
906
- g_autofree char * escaped_app = g_shell_quote (app );
932
+ g_autofree char * escaped_app = maybe_quote (app );
933
+ g_autofree char * escaped_branch = maybe_quote (branch );
934
+ g_autofree char * escaped_arch = maybe_quote (arch );
907
935
int i ;
908
936
909
937
if (!gs_file_openat_noatime (parent_fd , name , & desktop_fd , cancellable , error ))
@@ -940,13 +968,13 @@ export_desktop_file (const char *app,
940
968
g_key_file_remove_key (keyfile , groups [i ], "X-GNOME-Bugzilla-ExtraInfoScript" , NULL );
941
969
942
970
new_exec = g_string_new ("" );
943
- g_string_append_printf (new_exec , XDG_APP_BINDIR "/xdg-app run --branch='%s' --arch='%s' " , branch , arch );
971
+ g_string_append_printf (new_exec , XDG_APP_BINDIR "/xdg-app run --branch=%s --arch=%s " , escaped_branch , escaped_arch );
944
972
945
973
old_exec = g_key_file_get_string (keyfile , groups [i ], "Exec" , NULL );
946
974
if (old_exec && g_shell_parse_argv (old_exec , & old_argc , & old_argv , NULL ) && old_argc >= 1 )
947
975
{
948
976
int i ;
949
- g_autofree char * command = g_shell_quote (old_argv [0 ]);
977
+ g_autofree char * command = maybe_quote (old_argv [0 ]);
950
978
951
979
g_string_append_printf (new_exec , " --command=%s" , command );
952
980
@@ -955,7 +983,7 @@ export_desktop_file (const char *app,
955
983
956
984
for (i = 1 ; i < old_argc ; i ++ )
957
985
{
958
- g_autofree char * arg = g_shell_quote (old_argv [i ]);
986
+ g_autofree char * arg = maybe_quote (old_argv [i ]);
959
987
g_string_append (new_exec , " " );
960
988
g_string_append (new_exec , arg );
961
989
}
0 commit comments