From e175ff252f9abb7267000571207c9d612728e1b9 Mon Sep 17 00:00:00 2001 From: Denis Vlasenko Date: Tue, 26 Sep 2006 17:41:00 +0000 Subject: several fixes from openWRT project --- shell/ash.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'shell/ash.c') diff --git a/shell/ash.c b/shell/ash.c index 754c1d72b..7d4da434e 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -1384,6 +1384,13 @@ static const struct builtincmd builtincmd[] = { #define NUMBUILTINS (sizeof (builtincmd) / sizeof (struct builtincmd) ) +static const char *safe_applets[] = { + "[", "test", "echo", "cat", + "ln", "cp", "touch", "mkdir", "rm", + "cut", "hexdump", "awk", "sort", + "find", "xargs", "ls", "dd", + "chown", "chmod" +}; struct cmdentry { @@ -2034,6 +2041,19 @@ static int dotrap(void); static void setinteractive(int); static void exitshell(void) ATTRIBUTE_NORETURN; + +static int is_safe_applet(char *name) +{ + int n = sizeof(safe_applets) / sizeof(char *); + int i; + for (i = 0; i < n; i++) + if (strcmp(safe_applets[i], name) == 0) + return 1; + + return 0; +} + + /* * This routine is called when an error or an interrupt occurs in an * interactive shell and control is returned to the main command loop. @@ -3681,6 +3701,7 @@ shellexec(char **argv, const char *path, int idx) clearredir(1); envp = environment(); if (strchr(argv[0], '/') != NULL + || is_safe_applet(argv[0]) #ifdef CONFIG_FEATURE_SH_STANDALONE_SHELL || find_applet_by_name(argv[0]) #endif @@ -3723,6 +3744,18 @@ static void tryexec(char *cmd, char **argv, char **envp) { int repeated = 0; + struct BB_applet *a; + int argc = 0; + char **c; + + if(strchr(cmd, '/') == NULL && is_safe_applet(cmd) && (a = find_applet_by_name(cmd)) != NULL) { + c = argv; + while (*c != NULL) { + c++; argc++; + } + bb_applet_name = cmd; + exit(a->main(argc, argv)); + } #ifdef CONFIG_FEATURE_SH_STANDALONE_SHELL if(find_applet_by_name(cmd) != NULL) { /* re-exec ourselves with the new arguments */ @@ -3905,6 +3938,12 @@ find_command(char *name, struct cmdentry *entry, int act, const char *path) } #endif + if (is_safe_applet(name)) { + entry->cmdtype = CMDNORMAL; + entry->u.index = -1; + return; + } + updatetbl = (path == pathval()); if (!updatetbl) { act |= DO_ALTPATH; -- cgit v1.2.3