kwo pushed a commit to branch master.

http://git.enlightenment.org/e16/e16.git/commit/?id=5ee83dc8749e703e5219c8f0e3c69debbf6481b4

commit 5ee83dc8749e703e5219c8f0e3c69debbf6481b4
Author: Kim Woelders <k...@woelders.dk>
Date:   Mon Feb 14 17:42:02 2022 +0100

    Drop using shell to run menu (ipc exec) commands
    
    Instead do environment variable substitution when menus are loaded and
    run commands directly (with execvp()) without passing through shell.
---
 src/actions.c    | 28 ++++++++--------------------
 src/menus-misc.c |  8 +++++---
 2 files changed, 13 insertions(+), 23 deletions(-)

diff --git a/src/actions.c b/src/actions.c
index 1c166476..33569468 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -24,7 +24,6 @@
 #include "E.h"
 #include "desktops.h"
 #include "file.h"
-#include "user.h"
 
 static void
 _ExecSetStartupId(void)
@@ -87,17 +86,12 @@ Eexec(const char *cmd)
 int
 EspawnApplication(const char *params, int flags)
 {
-   char                exe[FILEPATH_LEN_MAX];
-   const char         *sh;
-   char               *real_exec;
+   int                 argc;
+   char              **argv;
 
    if (!params)
       return -1;
 
-   sscanf(params, "%4000s", exe);
-   if (exe[0] == '\0')
-      return -1;
-
    if (EDebug(EDBUG_TYPE_EXEC))
       Eprintf("%s: '%s'\n", __func__, params);
 
@@ -107,24 +101,18 @@ EspawnApplication(const char *params, int flags)
 
    _ExecSetupEnv(flags);
 
-   sh = usershell();
-
-   if (path_canexec(exe))
-     {
-       real_exec = EMALLOC(char, strlen(params) + 6);
-
-       if (!real_exec)
-          return -1;
-       sprintf(real_exec, "exec %s", params);
+   argv = StrlistDecodeEscaped(params, &argc);
+   if (argc <= 0)
+      return -1;
 
-       execl(sh, sh, "-c", real_exec, NULL);
-       /* We should not get here - invalid shell? */
-     }
+   execvp(argv[0], argv);
 
    if (!Mode.wm.startup)
       AlertOK(_("There was a problem running the command\n '%s'\nError: %m"),
              params);
 
+   StrlistFree(argv, argc);
+
    exit(100);
 }
 
diff --git a/src/menus-misc.c b/src/menus-misc.c
index b4547e7d..651a5a50 100644
--- a/src/menus-misc.c
+++ b/src/menus-misc.c
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various 
contributors
- * Copyright (C) 2004-2021 Kim Woelders
+ * Copyright (C) 2004-2022 Kim Woelders
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to
@@ -303,6 +303,7 @@ FillFlatFileMenu(Menu * m, const char *file)
        else
          {
             char               *txt, *icon, *act, *params;
+            char                cmd[4080];
             char                wd[4096];
             MenuItem           *mi;
             Menu               *mm;
@@ -316,9 +317,10 @@ FillFlatFileMenu(Menu * m, const char *file)
 
             if ((act) && (!strcmp(act, "exec")) && (params))
               {
-                 if (path_canexec0(params))
+                 EnvSubst(params, cmd, sizeof(cmd));
+                 if (path_canexec0(cmd))
                    {
-                      Esnprintf(wd, sizeof(wd), "exec %s", params);
+                      Esnprintf(wd, sizeof(wd), "exec %s", cmd);
                       mi = MenuItemCreate(txt, icon, wd, NULL);
                       MenuAddItem(m, mi);
                    }

-- 


Reply via email to