aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-12-26 21:31:11 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-12-26 21:31:11 +0000
commit8f27c34c28076e18890fea0a449578bad4ee6587 (patch)
treec9d54ae4fd247a9db9832097f179511298901f67
parent666da5e2c6edec979966d16771818b32dcfafe04 (diff)
downloadbusybox-w32-8f27c34c28076e18890fea0a449578bad4ee6587.tar.gz
busybox-w32-8f27c34c28076e18890fea0a449578bad4ee6587.tar.bz2
busybox-w32-8f27c34c28076e18890fea0a449578bad4ee6587.zip
ash: is_safe_applet mustn't affect disabled applets
-rw-r--r--shell/ash.c49
1 files changed, 33 insertions, 16 deletions
diff --git a/shell/ash.c b/shell/ash.c
index dcf77054f..6d96bce5a 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -1381,15 +1381,7 @@ static const struct builtincmd builtincmd[] = {
1381 { BUILTIN_REGULAR "wait", waitcmd }, 1381 { BUILTIN_REGULAR "wait", waitcmd },
1382}; 1382};
1383 1383
1384#define NUMBUILTINS (sizeof (builtincmd) / sizeof (struct builtincmd) ) 1384#define NUMBUILTINS (sizeof(builtincmd) / sizeof(builtincmd[0]))
1385
1386static const char *safe_applets[] = {
1387 "[", "test", "echo", "cat",
1388 "ln", "cp", "touch", "mkdir", "rm",
1389 "cut", "hexdump", "awk", "sort",
1390 "find", "xargs", "ls", "dd",
1391 "chown", "chmod"
1392};
1393 1385
1394 1386
1395struct cmdentry { 1387struct cmdentry {
@@ -2042,7 +2034,30 @@ static void exitshell(void) ATTRIBUTE_NORETURN;
2042 2034
2043static int is_safe_applet(char *name) 2035static int is_safe_applet(char *name)
2044{ 2036{
2045 int n = sizeof(safe_applets) / sizeof(char *); 2037 /* It isn't a bug to have non-existent applet here... */
2038 /* ...just a waste of space... */
2039 static const char safe_applets[][8] = {
2040 "["
2041 USE_AWK (, "awk" )
2042 USE_CAT (, "cat" )
2043 USE_CHMOD (, "chmod" )
2044 USE_CHOWN (, "chown" )
2045 USE_CP (, "cp" )
2046 USE_CUT (, "cut" )
2047 USE_DD (, "dd" )
2048 USE_ECHO (, "echo" )
2049 USE_FIND (, "find" )
2050 USE_HEXDUMP(, "hexdump")
2051 USE_LN (, "ln" )
2052 USE_LS (, "ls" )
2053 USE_MKDIR (, "mkdir" )
2054 USE_RM (, "rm" )
2055 USE_SORT (, "sort" )
2056 USE_TEST (, "test" )
2057 USE_TOUCH (, "touch" )
2058 USE_XARGS (, "xargs" )
2059 };
2060 int n = sizeof(safe_applets) / sizeof(safe_applets[0]);
2046 int i; 2061 int i;
2047 for (i = 0; i < n; i++) 2062 for (i = 0; i < n; i++)
2048 if (strcmp(safe_applets[i], name) == 0) 2063 if (strcmp(safe_applets[i], name) == 0)
@@ -3702,12 +3717,11 @@ shellexec(char **argv, const char *path, int idx)
3702 3717
3703 clearredir(1); 3718 clearredir(1);
3704 envp = environment(); 3719 envp = environment();
3705 if (strchr(argv[0], '/') != NULL 3720 if (strchr(argv[0], '/')
3706 || is_safe_applet(argv[0])
3707#ifdef CONFIG_FEATURE_SH_STANDALONE_SHELL 3721#ifdef CONFIG_FEATURE_SH_STANDALONE_SHELL
3708 || find_applet_by_name(argv[0]) 3722 || find_applet_by_name(argv[0])
3709#endif 3723#endif
3710 ) { 3724 ) {
3711 tryexec(argv[0], argv, envp); 3725 tryexec(argv[0], argv, envp);
3712 e = errno; 3726 e = errno;
3713 } else { 3727 } else {
@@ -3750,7 +3764,10 @@ tryexec(char *cmd, char **argv, char **envp)
3750 int argc = 0; 3764 int argc = 0;
3751 char **c; 3765 char **c;
3752 3766
3753 if(strchr(cmd, '/') == NULL && is_safe_applet(cmd) && (a = find_applet_by_name(cmd)) != NULL) { 3767 if (strchr(cmd, '/') == NULL
3768 && (a = find_applet_by_name(cmd)) != NULL
3769 && is_safe_applet(cmd)
3770 ) {
3754 c = argv; 3771 c = argv;
3755 while (*c != NULL) { 3772 while (*c != NULL) {
3756 c++; argc++; 3773 c++; argc++;
@@ -3759,7 +3776,7 @@ tryexec(char *cmd, char **argv, char **envp)
3759 exit(a->main(argc, argv)); 3776 exit(a->main(argc, argv));
3760 } 3777 }
3761#ifdef CONFIG_FEATURE_SH_STANDALONE_SHELL 3778#ifdef CONFIG_FEATURE_SH_STANDALONE_SHELL
3762 if(find_applet_by_name(cmd) != NULL) { 3779 if (find_applet_by_name(cmd) != NULL) {
3763 /* re-exec ourselves with the new arguments */ 3780 /* re-exec ourselves with the new arguments */
3764 execve(CONFIG_BUSYBOX_EXEC_PATH,argv,envp); 3781 execve(CONFIG_BUSYBOX_EXEC_PATH,argv,envp);
3765 /* If they called chroot or otherwise made the binary no longer 3782 /* If they called chroot or otherwise made the binary no longer