aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-09-26 17:41:00 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-09-26 17:41:00 +0000
commite175ff252f9abb7267000571207c9d612728e1b9 (patch)
treebc6843cbc8ca3d0d2257a9e2349c03358b70b85a /shell
parent22f6dcb47c32909ca0a3d720b11df5ea86b1e76c (diff)
downloadbusybox-e175ff252f9abb7267000571207c9d612728e1b9.tar.gz
several fixes from openWRT project
Diffstat (limited to 'shell')
-rw-r--r--shell/ash.c39
1 files changed, 39 insertions, 0 deletions
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;