aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlandley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-07-09 17:03:07 +0000
committerlandley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-07-09 17:03:07 +0000
commitae599be02474a7499086f7f31424562765efd783 (patch)
tree9167da0570b4f1937da1231ec01063b4d2b71027
parent3ce6b55634d6ec96310576e6f3924f385abfb5a7 (diff)
downloadbusybox-w32-ae599be02474a7499086f7f31424562765efd783.tar.gz
busybox-w32-ae599be02474a7499086f7f31424562765efd783.tar.bz2
busybox-w32-ae599be02474a7499086f7f31424562765efd783.zip
Bugfix from Shaun Jackman (check that argv[optind] isn't null before
dereferencing it) plus a bunch of tweaks from me. git-svn-id: svn://busybox.net/trunk/busybox@15670 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r--shell/lash.c35
1 files changed, 16 insertions, 19 deletions
diff --git a/shell/lash.c b/shell/lash.c
index 83baee29d..c5aaf1d1f 100644
--- a/shell/lash.c
+++ b/shell/lash.c
@@ -1498,6 +1498,8 @@ static void free_memory(void)
1498 remove_job(&job_list, job_list.fg); 1498 remove_job(&job_list, job_list.fg);
1499 } 1499 }
1500} 1500}
1501#else
1502void free_memory(void);
1501#endif 1503#endif
1502 1504
1503#ifdef CONFIG_LASH_JOB_CONTROL 1505#ifdef CONFIG_LASH_JOB_CONTROL
@@ -1528,7 +1530,7 @@ static void setup_job_control(void)
1528 /* Put ourselves in our own process group. */ 1530 /* Put ourselves in our own process group. */
1529 setsid(); 1531 setsid();
1530 shell_pgrp = getpid (); 1532 shell_pgrp = getpid ();
1531 setpgid (shell_pgrp, shell_pgrp); 1533 setpgid(shell_pgrp, shell_pgrp);
1532 1534
1533 /* Grab control of the terminal. */ 1535 /* Grab control of the terminal. */
1534 tcsetpgrp(shell_terminal, shell_pgrp); 1536 tcsetpgrp(shell_terminal, shell_pgrp);
@@ -1577,7 +1579,7 @@ int lash_main(int argc_l, char **argv_l)
1577 argv = argv+optind; 1579 argv = argv+optind;
1578 break; 1580 break;
1579 case 'i': 1581 case 'i':
1580 interactive = TRUE; 1582 interactive++;
1581 break; 1583 break;
1582 default: 1584 default:
1583 bb_show_usage(); 1585 bb_show_usage();
@@ -1591,18 +1593,18 @@ int lash_main(int argc_l, char **argv_l)
1591 * standard output is a terminal 1593 * standard output is a terminal
1592 * Refer to Posix.2, the description of the `sh' utility. */ 1594 * Refer to Posix.2, the description of the `sh' utility. */
1593 if (argv[optind]==NULL && input==stdin && 1595 if (argv[optind]==NULL && input==stdin &&
1594 isatty(STDIN_FILENO) && isatty(STDOUT_FILENO)) { 1596 isatty(STDIN_FILENO) && isatty(STDOUT_FILENO))
1595 interactive=TRUE; 1597 {
1598 interactive++;
1596 } 1599 }
1597 setup_job_control(); 1600 setup_job_control();
1598 if (interactive==TRUE) { 1601 if (interactive) {
1599 //printf( "optind=%d argv[optind]='%s'\n", optind, argv[optind]);
1600 /* Looks like they want an interactive shell */ 1602 /* Looks like they want an interactive shell */
1601#ifndef CONFIG_FEATURE_SH_EXTRA_QUIET 1603 if (!ENABLE_FEATURE_SH_EXTRA_QUIET) {
1602 printf( "\n\n%s Built-in shell (lash)\n", BB_BANNER); 1604 printf( "\n\n%s Built-in shell (lash)\n", BB_BANNER);
1603 printf( "Enter 'help' for a list of built-in commands.\n\n"); 1605 printf( "Enter 'help' for a list of built-in commands.\n\n");
1604#endif 1606 }
1605 } else if (local_pending_command==NULL) { 1607 } else if (!local_pending_command && argv[optind]) {
1606 //printf( "optind=%d argv[optind]='%s'\n", optind, argv[optind]); 1608 //printf( "optind=%d argv[optind]='%s'\n", optind, argv[optind]);
1607 input = bb_xfopen(argv[optind], "r"); 1609 input = bb_xfopen(argv[optind], "r");
1608 /* be lazy, never mark this closed */ 1610 /* be lazy, never mark this closed */
@@ -1614,15 +1616,10 @@ int lash_main(int argc_l, char **argv_l)
1614 if (!cwd) 1616 if (!cwd)
1615 cwd = bb_msg_unknown; 1617 cwd = bb_msg_unknown;
1616 1618
1617#ifdef CONFIG_FEATURE_CLEAN_UP 1619 if (ENABLE_FEATURE_CLEAN_UP) atexit(free_memory);
1618 atexit(free_memory);
1619#endif
1620 1620
1621#ifdef CONFIG_FEATURE_COMMAND_EDITING 1621 if (ENABLE_FEATURE_COMMAND_EDITING) cmdedit_set_initial_prompt();
1622 cmdedit_set_initial_prompt(); 1622 else PS1 = NULL;
1623#else
1624 PS1 = NULL;
1625#endif
1626 1623
1627 return (busy_loop(input)); 1624 return (busy_loop(input));
1628} 1625}