[gnome-settings-daemon] media-keys: Escape custom command for execution



commit 333b89eb848e95a189d6ff5653bd3f47c2c79f32
Author: Benjamin Berg <bberg redhat com>
Date:   Fri Jun 22 11:54:05 2018 +0200

    media-keys: Escape custom command for execution
    
    g_app_info_create_from_commandline interprets the % character of
    commands that are entered by the user. So escape all % characters by
    doubling them so that they are not stripped from the resulting command
    line.
    
    Fixes: https://gitlab.gnome.org/GNOME/gnome-settings-daemon/issues/34

 plugins/media-keys/gsd-media-keys-manager.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
---
diff --git a/plugins/media-keys/gsd-media-keys-manager.c b/plugins/media-keys/gsd-media-keys-manager.c
index 7925b513..092f0665 100644
--- a/plugins/media-keys/gsd-media-keys-manager.c
+++ b/plugins/media-keys/gsd-media-keys-manager.c
@@ -903,8 +903,25 @@ execute (GsdMediaKeysManager *manager,
          gint64               timestamp)
 {
        GAppInfo *app_info;
+       g_autofree gchar *escaped = NULL;
+       gchar *p;
+
+       /* Escape all % characters as g_app_info_create_from_commandline will
+        * try to interpret them otherwise. */
+       escaped = g_malloc (strlen (cmd) * 2 + 1);
+       p = escaped;
+       while (*cmd) {
+               *p = *cmd;
+               p++;
+               if (*cmd == '%') {
+                       *p = '%';
+                       p++;
+               }
+               cmd++;
+       }
+       *p = '\0';
 
-       app_info = g_app_info_create_from_commandline (cmd, NULL, G_APP_INFO_CREATE_NONE, NULL);
+       app_info = g_app_info_create_from_commandline (escaped, NULL, G_APP_INFO_CREATE_NONE, NULL);
        launch_app (manager, app_info, timestamp);
        g_object_unref (app_info);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]