diff options
author | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-09-26 17:41:00 +0000 |
---|---|---|
committer | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-09-26 17:41:00 +0000 |
commit | acf1aba1e59ea3e2c76106b8dd6aad15191ada33 (patch) | |
tree | bc6843cbc8ca3d0d2257a9e2349c03358b70b85a /shell | |
parent | 40c74e75a0139de991873f099aa350509955cf06 (diff) | |
download | busybox-w32-acf1aba1e59ea3e2c76106b8dd6aad15191ada33.tar.gz busybox-w32-acf1aba1e59ea3e2c76106b8dd6aad15191ada33.tar.bz2 busybox-w32-acf1aba1e59ea3e2c76106b8dd6aad15191ada33.zip |
several fixes from openWRT project
git-svn-id: svn://busybox.net/trunk/busybox@16229 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'shell')
-rw-r--r-- | shell/ash.c | 39 |
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[] = { | |||
1384 | 1384 | ||
1385 | #define NUMBUILTINS (sizeof (builtincmd) / sizeof (struct builtincmd) ) | 1385 | #define NUMBUILTINS (sizeof (builtincmd) / sizeof (struct builtincmd) ) |
1386 | 1386 | ||
1387 | static const char *safe_applets[] = { | ||
1388 | "[", "test", "echo", "cat", | ||
1389 | "ln", "cp", "touch", "mkdir", "rm", | ||
1390 | "cut", "hexdump", "awk", "sort", | ||
1391 | "find", "xargs", "ls", "dd", | ||
1392 | "chown", "chmod" | ||
1393 | }; | ||
1387 | 1394 | ||
1388 | 1395 | ||
1389 | struct cmdentry { | 1396 | struct cmdentry { |
@@ -2034,6 +2041,19 @@ static int dotrap(void); | |||
2034 | static void setinteractive(int); | 2041 | static void setinteractive(int); |
2035 | static void exitshell(void) ATTRIBUTE_NORETURN; | 2042 | static void exitshell(void) ATTRIBUTE_NORETURN; |
2036 | 2043 | ||
2044 | |||
2045 | static int is_safe_applet(char *name) | ||
2046 | { | ||
2047 | int n = sizeof(safe_applets) / sizeof(char *); | ||
2048 | int i; | ||
2049 | for (i = 0; i < n; i++) | ||
2050 | if (strcmp(safe_applets[i], name) == 0) | ||
2051 | return 1; | ||
2052 | |||
2053 | return 0; | ||
2054 | } | ||
2055 | |||
2056 | |||
2037 | /* | 2057 | /* |
2038 | * This routine is called when an error or an interrupt occurs in an | 2058 | * This routine is called when an error or an interrupt occurs in an |
2039 | * interactive shell and control is returned to the main command loop. | 2059 | * interactive shell and control is returned to the main command loop. |
@@ -3681,6 +3701,7 @@ shellexec(char **argv, const char *path, int idx) | |||
3681 | clearredir(1); | 3701 | clearredir(1); |
3682 | envp = environment(); | 3702 | envp = environment(); |
3683 | if (strchr(argv[0], '/') != NULL | 3703 | if (strchr(argv[0], '/') != NULL |
3704 | || is_safe_applet(argv[0]) | ||
3684 | #ifdef CONFIG_FEATURE_SH_STANDALONE_SHELL | 3705 | #ifdef CONFIG_FEATURE_SH_STANDALONE_SHELL |
3685 | || find_applet_by_name(argv[0]) | 3706 | || find_applet_by_name(argv[0]) |
3686 | #endif | 3707 | #endif |
@@ -3723,6 +3744,18 @@ static void | |||
3723 | tryexec(char *cmd, char **argv, char **envp) | 3744 | tryexec(char *cmd, char **argv, char **envp) |
3724 | { | 3745 | { |
3725 | int repeated = 0; | 3746 | int repeated = 0; |
3747 | struct BB_applet *a; | ||
3748 | int argc = 0; | ||
3749 | char **c; | ||
3750 | |||
3751 | if(strchr(cmd, '/') == NULL && is_safe_applet(cmd) && (a = find_applet_by_name(cmd)) != NULL) { | ||
3752 | c = argv; | ||
3753 | while (*c != NULL) { | ||
3754 | c++; argc++; | ||
3755 | } | ||
3756 | bb_applet_name = cmd; | ||
3757 | exit(a->main(argc, argv)); | ||
3758 | } | ||
3726 | #ifdef CONFIG_FEATURE_SH_STANDALONE_SHELL | 3759 | #ifdef CONFIG_FEATURE_SH_STANDALONE_SHELL |
3727 | if(find_applet_by_name(cmd) != NULL) { | 3760 | if(find_applet_by_name(cmd) != NULL) { |
3728 | /* re-exec ourselves with the new arguments */ | 3761 | /* re-exec ourselves with the new arguments */ |
@@ -3905,6 +3938,12 @@ find_command(char *name, struct cmdentry *entry, int act, const char *path) | |||
3905 | } | 3938 | } |
3906 | #endif | 3939 | #endif |
3907 | 3940 | ||
3941 | if (is_safe_applet(name)) { | ||
3942 | entry->cmdtype = CMDNORMAL; | ||
3943 | entry->u.index = -1; | ||
3944 | return; | ||
3945 | } | ||
3946 | |||
3908 | updatetbl = (path == pathval()); | 3947 | updatetbl = (path == pathval()); |
3909 | if (!updatetbl) { | 3948 | if (!updatetbl) { |
3910 | act |= DO_ALTPATH; | 3949 | act |= DO_ALTPATH; |