X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=shell%2Fash.c;h=6d96bce5aefb48288d9449017d6a36f83a07ffde;hb=98ee06d3d46aa7f89c204681c7075b53300a6a6e;hp=97f0d6befce48949d3c5bbf83fd84e94ca1ea658;hpb=15b213ef5a0834eb06a0183ab839ac883d829d5a;p=oweals%2Fbusybox.git diff --git a/shell/ash.c b/shell/ash.c index 97f0d6bef..6d96bce5a 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -85,7 +85,7 @@ #ifdef CONFIG_ASH_JOB_CONTROL #define JOBS 1 #else -#undef JOBS +#define JOBS 0 #endif #if JOBS || defined(CONFIG_ASH_READ_NCHARS) @@ -1381,15 +1381,7 @@ static const struct builtincmd builtincmd[] = { { BUILTIN_REGULAR "wait", waitcmd }, }; -#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" -}; +#define NUMBUILTINS (sizeof(builtincmd) / sizeof(builtincmd[0])) struct cmdentry { @@ -2042,7 +2034,30 @@ static void exitshell(void) ATTRIBUTE_NORETURN; static int is_safe_applet(char *name) { - int n = sizeof(safe_applets) / sizeof(char *); + /* It isn't a bug to have non-existent applet here... */ + /* ...just a waste of space... */ + static const char safe_applets[][8] = { + "[" + USE_AWK (, "awk" ) + USE_CAT (, "cat" ) + USE_CHMOD (, "chmod" ) + USE_CHOWN (, "chown" ) + USE_CP (, "cp" ) + USE_CUT (, "cut" ) + USE_DD (, "dd" ) + USE_ECHO (, "echo" ) + USE_FIND (, "find" ) + USE_HEXDUMP(, "hexdump") + USE_LN (, "ln" ) + USE_LS (, "ls" ) + USE_MKDIR (, "mkdir" ) + USE_RM (, "rm" ) + USE_SORT (, "sort" ) + USE_TEST (, "test" ) + USE_TOUCH (, "touch" ) + USE_XARGS (, "xargs" ) + }; + int n = sizeof(safe_applets) / sizeof(safe_applets[0]); int i; for (i = 0; i < n; i++) if (strcmp(safe_applets[i], name) == 0) @@ -2402,7 +2417,7 @@ static const char * updatepwd(const char *dir) } p = strtok(cdcomppath, "/"); while (p) { - switch(*p) { + switch (*p) { case '.': if (p[1] == '.' && p[2] == '\0') { while (new > lim) { @@ -3702,12 +3717,11 @@ shellexec(char **argv, const char *path, int idx) clearredir(1); envp = environment(); - if (strchr(argv[0], '/') != NULL - || is_safe_applet(argv[0]) + if (strchr(argv[0], '/') #ifdef CONFIG_FEATURE_SH_STANDALONE_SHELL - || find_applet_by_name(argv[0]) + || find_applet_by_name(argv[0]) #endif - ) { + ) { tryexec(argv[0], argv, envp); e = errno; } else { @@ -3750,7 +3764,10 @@ tryexec(char *cmd, char **argv, char **envp) int argc = 0; char **c; - if(strchr(cmd, '/') == NULL && is_safe_applet(cmd) && (a = find_applet_by_name(cmd)) != NULL) { + if (strchr(cmd, '/') == NULL + && (a = find_applet_by_name(cmd)) != NULL + && is_safe_applet(cmd) + ) { c = argv; while (*c != NULL) { c++; argc++; @@ -3759,7 +3776,7 @@ tryexec(char *cmd, char **argv, char **envp) exit(a->main(argc, argv)); } #ifdef CONFIG_FEATURE_SH_STANDALONE_SHELL - if(find_applet_by_name(cmd) != NULL) { + if (find_applet_by_name(cmd) != NULL) { /* re-exec ourselves with the new arguments */ execve(CONFIG_BUSYBOX_EXEC_PATH,argv,envp); /* If they called chroot or otherwise made the binary no longer @@ -4802,7 +4819,7 @@ exptilde(char *startp, char *p, int flag) name = p + 1; while ((c = *++p) != '\0') { - switch(c) { + switch (c) { case CTLESC: return startp; case CTLQUOTEMARK: @@ -6647,7 +6664,7 @@ usage: } #endif /* JOBS */ -#if defined(JOBS) || DEBUG +#if JOBS || DEBUG static int jobno(const struct job *jp) { @@ -8172,7 +8189,7 @@ exitcmd(int argc, char **argv) static int echocmd(int argc, char **argv) { - return bb_echo(argc, argv); + return bb_echo(argv); } #endif @@ -10211,7 +10228,7 @@ readtoken1(int firstc, int syntax, char *eofmark, int striptabs) CHECKEND(); /* set c to PEOF if at end of here document */ for (;;) { /* until end of line or end of word */ CHECKSTRSPACE(4, out); /* permit 4 calls to USTPUTC */ - switch(SIT(c, syntax)) { + switch (SIT(c, syntax)) { case CNL: /* '\n' */ if (syntax == BASESYNTAX) goto endword; /* exit outer loop */ @@ -11282,7 +11299,7 @@ shtree(union node *n, int ind, char *pfx, FILE *fp) return; indent(ind, pfx, fp); - switch(n->type) { + switch (n->type) { case NSEMI: s = "; "; goto binop; @@ -11893,17 +11910,11 @@ static int helpcmd(int argc, char **argv) } } #ifdef CONFIG_FEATURE_SH_STANDALONE_SHELL - { - extern const struct BB_applet applets[]; - extern const size_t NUM_APPLETS; - - for (i = 0; i < NUM_APPLETS; i++) { - - col += out1fmt("%c%s", ((col == 0) ? '\t' : ' '), applets[i].name); - if (col > 60) { - out1fmt("\n"); - col = 0; - } + for (i = 0; i < NUM_APPLETS; i++) { + col += out1fmt("%c%s", ((col == 0) ? '\t' : ' '), applets[i].name); + if (col > 60) { + out1fmt("\n"); + col = 0; } } #endif @@ -12619,7 +12630,7 @@ readcmd(int argc, char **argv) while ((i = nextopt("p:r")) != '\0') #endif { - switch(i) { + switch (i) { case 'p': prompt = optionarg; break; @@ -12693,7 +12704,7 @@ readcmd(int argc, char **argv) FD_ZERO (&set); FD_SET (0, &set); - i = select (FD_SETSIZE, &set, NULL, NULL, &ts); + i = select(FD_SETSIZE, &set, NULL, NULL, &ts); if (!i) { #if defined(CONFIG_ASH_READ_NCHARS) if (nch_flag) @@ -13585,7 +13596,7 @@ static arith_t arith (const char *expr, int *perrcode) * a number, since it evaluates to one). Think about it. * It makes sense. */ if (lasttok != TOK_NUM) { - switch(op) { + switch (op) { case TOK_ADD: op = TOK_UPLUS; break;