diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-03-31 11:08:50 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-03-31 11:08:50 +0000 |
commit | f443bffd3c24c4b7fcbc0472c75e747e26c24fef (patch) | |
tree | 1a3f2288876dbe660b5f73c0b275821c6f8094d6 | |
parent | 6fa8b8e17f8b3ceb16172fe64fcc97860bf79d21 (diff) | |
download | busybox-w32-f443bffd3c24c4b7fcbc0472c75e747e26c24fef.tar.gz busybox-w32-f443bffd3c24c4b7fcbc0472c75e747e26c24fef.tar.bz2 busybox-w32-f443bffd3c24c4b7fcbc0472c75e747e26c24fef.zip |
lash: make -c work; crush buffer overrun and free of non-malloced ptr
(from Mats Erik Andersson <mats.andersson64@comhem.se>)
-rw-r--r-- | shell/lash.c | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/shell/lash.c b/shell/lash.c index 99b6173bf..58d770fd8 100644 --- a/shell/lash.c +++ b/shell/lash.c | |||
@@ -114,7 +114,7 @@ static int builtin_read(struct child_prog *cmd); | |||
114 | /* function prototypes for shell stuff */ | 114 | /* function prototypes for shell stuff */ |
115 | static void checkjobs(struct jobset *job_list); | 115 | static void checkjobs(struct jobset *job_list); |
116 | static void remove_job(struct jobset *j_list, struct job *job); | 116 | static void remove_job(struct jobset *j_list, struct job *job); |
117 | static int get_command(FILE * source, char *command); | 117 | static int get_command_bufsiz(FILE * source, char *command); |
118 | static int parse_command(char **command_ptr, struct job *job, int *inbg); | 118 | static int parse_command(char **command_ptr, struct job *job, int *inbg); |
119 | static int run_command(struct job *newjob, int inbg, int outpipe[2]); | 119 | static int run_command(struct job *newjob, int inbg, int outpipe[2]); |
120 | static int pseudo_exec(struct child_prog *cmd) ATTRIBUTE_NORETURN; | 120 | static int pseudo_exec(struct child_prog *cmd) ATTRIBUTE_NORETURN; |
@@ -649,15 +649,14 @@ static inline const char* setup_prompt_string(void) | |||
649 | static line_input_t *line_input_state; | 649 | static line_input_t *line_input_state; |
650 | #endif | 650 | #endif |
651 | 651 | ||
652 | static int get_command(FILE * source, char *command) | 652 | static int get_command_bufsiz(FILE * source, char *command) |
653 | { | 653 | { |
654 | const char *prompt_str; | 654 | const char *prompt_str; |
655 | 655 | ||
656 | if (source == NULL) { | 656 | if (source == NULL) { |
657 | if (local_pending_command) { | 657 | if (local_pending_command) { |
658 | /* a command specified (-c option): return it & mark it done */ | 658 | /* a command specified (-c option): return it & mark it done */ |
659 | strcpy(command, local_pending_command); | 659 | strncpy(command, local_pending_command, BUFSIZ); |
660 | free(local_pending_command); | ||
661 | local_pending_command = NULL; | 660 | local_pending_command = NULL; |
662 | return 0; | 661 | return 0; |
663 | } | 662 | } |
@@ -1363,12 +1362,12 @@ static int busy_loop(FILE * input) | |||
1363 | checkjobs(&job_list); | 1362 | checkjobs(&job_list); |
1364 | 1363 | ||
1365 | if (!next_command) { | 1364 | if (!next_command) { |
1366 | if (get_command(input, command)) | 1365 | if (get_command_bufsiz(input, command)) |
1367 | break; | 1366 | break; |
1368 | next_command = command; | 1367 | next_command = command; |
1369 | } | 1368 | } |
1370 | 1369 | ||
1371 | if (! expand_arguments(next_command)) { | 1370 | if (!expand_arguments(next_command)) { |
1372 | free(command); | 1371 | free(command); |
1373 | command = xzalloc(BUFSIZ); | 1372 | command = xzalloc(BUFSIZ); |
1374 | next_command = NULL; | 1373 | next_command = NULL; |
@@ -1455,8 +1454,6 @@ static void free_memory(void) | |||
1455 | if (cwd && cwd != bb_msg_unknown) { | 1454 | if (cwd && cwd != bb_msg_unknown) { |
1456 | free((char*)cwd); | 1455 | free((char*)cwd); |
1457 | } | 1456 | } |
1458 | if (local_pending_command) | ||
1459 | free(local_pending_command); | ||
1460 | 1457 | ||
1461 | if (job_list.fg && !job_list.fg->running_progs) { | 1458 | if (job_list.fg && !job_list.fg->running_progs) { |
1462 | remove_job(&job_list, job_list.fg); | 1459 | remove_job(&job_list, job_list.fg); |
@@ -1538,7 +1535,7 @@ int lash_main(int argc_l, char **argv_l) | |||
1538 | 1535 | ||
1539 | opt = getopt32(argc_l, argv_l, "+ic:", &local_pending_command); | 1536 | opt = getopt32(argc_l, argv_l, "+ic:", &local_pending_command); |
1540 | #define LASH_OPT_i (1<<0) | 1537 | #define LASH_OPT_i (1<<0) |
1541 | #define LASH_OPT_c (1<<2) | 1538 | #define LASH_OPT_c (1<<1) |
1542 | if (opt & LASH_OPT_c) { | 1539 | if (opt & LASH_OPT_c) { |
1543 | input = NULL; | 1540 | input = NULL; |
1544 | optind++; | 1541 | optind++; |