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.
This commit is contained in:
Kim Woelders 2022-02-14 17:42:02 +01:00
parent 52d8dfe805
commit 5ee83dc874
2 changed files with 13 additions and 23 deletions

View File

@ -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();
argv = StrlistDecodeEscaped(params, &argc);
if (argc <= 0)
return -1;
if (path_canexec(exe))
{
real_exec = EMALLOC(char, strlen(params) + 6);
if (!real_exec)
return -1;
sprintf(real_exec, "exec %s", params);
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);
}

View File

@ -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);
}