mirror of
https://github.com/sheumann/hush.git
synced 2025-01-03 00:31:16 +00:00
ash: do not do find_applet() twice in shellexec/tryexec
This commit is contained in:
parent
55e06c1edf
commit
4a9ca13fe7
42
shell/ash.c
42
shell/ash.c
@ -6881,21 +6881,18 @@ static int builtinloc = -1; /* index in path of %builtin, or -1 */
|
|||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
tryexec(char *cmd, char **argv, char **envp)
|
tryexec(USE_FEATURE_SH_STANDALONE(int applet_no,) char *cmd, char **argv, char **envp)
|
||||||
{
|
{
|
||||||
int repeated = 0;
|
int repeated = 0;
|
||||||
|
|
||||||
#if ENABLE_FEATURE_SH_STANDALONE
|
#if ENABLE_FEATURE_SH_STANDALONE
|
||||||
if (strchr(cmd, '/') == NULL) {
|
if (applet_no >= 0) {
|
||||||
int a = find_applet_by_name(cmd);
|
if (APPLET_IS_NOEXEC(applet_no))
|
||||||
if (a >= 0) {
|
run_applet_no_and_exit(applet_no, argv);
|
||||||
if (APPLET_IS_NOEXEC(a))
|
/* re-exec ourselves with the new arguments */
|
||||||
run_applet_no_and_exit(a, argv);
|
execve(bb_busybox_exec_path, argv, envp);
|
||||||
/* re-exec ourselves with the new arguments */
|
/* If they called chroot or otherwise made the binary no longer
|
||||||
execve(bb_busybox_exec_path, argv, envp);
|
* executable, fall through */
|
||||||
/* If they called chroot or otherwise made the binary no longer
|
|
||||||
* executable, fall through */
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -6931,7 +6928,6 @@ tryexec(char *cmd, char **argv, char **envp)
|
|||||||
* Exec a program. Never returns. If you change this routine, you may
|
* Exec a program. Never returns. If you change this routine, you may
|
||||||
* have to change the find_command routine as well.
|
* have to change the find_command routine as well.
|
||||||
*/
|
*/
|
||||||
#define environment() listvars(VEXPORT, VUNSET, 0)
|
|
||||||
static void shellexec(char **, const char *, int) ATTRIBUTE_NORETURN;
|
static void shellexec(char **, const char *, int) ATTRIBUTE_NORETURN;
|
||||||
static void
|
static void
|
||||||
shellexec(char **argv, const char *path, int idx)
|
shellexec(char **argv, const char *path, int idx)
|
||||||
@ -6940,21 +6936,24 @@ shellexec(char **argv, const char *path, int idx)
|
|||||||
int e;
|
int e;
|
||||||
char **envp;
|
char **envp;
|
||||||
int exerrno;
|
int exerrno;
|
||||||
|
#if ENABLE_FEATURE_SH_STANDALONE
|
||||||
|
int applet_no = -1;
|
||||||
|
#endif
|
||||||
|
|
||||||
clearredir(1);
|
clearredir(1);
|
||||||
envp = environment();
|
envp = listvars(VEXPORT, VUNSET, 0);
|
||||||
if (strchr(argv[0], '/')
|
if (strchr(argv[0], '/') != NULL
|
||||||
#if ENABLE_FEATURE_SH_STANDALONE
|
#if ENABLE_FEATURE_SH_STANDALONE
|
||||||
|| find_applet_by_name(argv[0]) >= 0
|
|| (applet_no = find_applet_by_name(argv[0])) >= 0
|
||||||
#endif
|
#endif
|
||||||
) {
|
) {
|
||||||
tryexec(argv[0], argv, envp);
|
tryexec(USE_FEATURE_SH_STANDALONE(applet_no,) argv[0], argv, envp);
|
||||||
e = errno;
|
e = errno;
|
||||||
} else {
|
} else {
|
||||||
e = ENOENT;
|
e = ENOENT;
|
||||||
while ((cmdname = padvance(&path, argv[0])) != NULL) {
|
while ((cmdname = padvance(&path, argv[0])) != NULL) {
|
||||||
if (--idx < 0 && pathopt == NULL) {
|
if (--idx < 0 && pathopt == NULL) {
|
||||||
tryexec(cmdname, argv, envp);
|
tryexec(USE_FEATURE_SH_STANDALONE(-1,) cmdname, argv, envp);
|
||||||
if (errno != ENOENT && errno != ENOTDIR)
|
if (errno != ENOENT && errno != ENOTDIR)
|
||||||
e = errno;
|
e = errno;
|
||||||
}
|
}
|
||||||
@ -11630,11 +11629,10 @@ find_command(char *name, struct cmdentry *entry, int act, const char *path)
|
|||||||
if (bcmd)
|
if (bcmd)
|
||||||
goto builtin_success;
|
goto builtin_success;
|
||||||
continue;
|
continue;
|
||||||
} else if (!(act & DO_NOFUNC)
|
}
|
||||||
&& prefix(pathopt, "func")) {
|
if ((act & DO_NOFUNC)
|
||||||
/* handled below */
|
|| !prefix(pathopt, "func")
|
||||||
} else {
|
) { /* ignore unimplemented options */
|
||||||
/* ignore unimplemented options */
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user