Bugfix from Shaun Jackman (check that argv[optind] isn't null before

dereferencing it) plus a bunch of tweaks from me.
This commit is contained in:
Rob Landley 2006-07-09 17:03:07 +00:00
parent 1df45cf8e7
commit acf448d4f6

View File

@ -1498,6 +1498,8 @@ static void free_memory(void)
remove_job(&job_list, job_list.fg);
}
}
#else
void free_memory(void);
#endif
#ifdef CONFIG_LASH_JOB_CONTROL
@ -1528,7 +1530,7 @@ static void setup_job_control(void)
/* Put ourselves in our own process group. */
setsid();
shell_pgrp = getpid ();
setpgid (shell_pgrp, shell_pgrp);
setpgid(shell_pgrp, shell_pgrp);
/* Grab control of the terminal. */
tcsetpgrp(shell_terminal, shell_pgrp);
@ -1577,7 +1579,7 @@ int lash_main(int argc_l, char **argv_l)
argv = argv+optind;
break;
case 'i':
interactive = TRUE;
interactive++;
break;
default:
bb_show_usage();
@ -1591,18 +1593,18 @@ int lash_main(int argc_l, char **argv_l)
* standard output is a terminal
* Refer to Posix.2, the description of the `sh' utility. */
if (argv[optind]==NULL && input==stdin &&
isatty(STDIN_FILENO) && isatty(STDOUT_FILENO)) {
interactive=TRUE;
isatty(STDIN_FILENO) && isatty(STDOUT_FILENO))
{
interactive++;
}
setup_job_control();
if (interactive==TRUE) {
//printf( "optind=%d argv[optind]='%s'\n", optind, argv[optind]);
if (interactive) {
/* Looks like they want an interactive shell */
#ifndef CONFIG_FEATURE_SH_EXTRA_QUIET
printf( "\n\n%s Built-in shell (lash)\n", BB_BANNER);
printf( "Enter 'help' for a list of built-in commands.\n\n");
#endif
} else if (local_pending_command==NULL) {
if (!ENABLE_FEATURE_SH_EXTRA_QUIET) {
printf( "\n\n%s Built-in shell (lash)\n", BB_BANNER);
printf( "Enter 'help' for a list of built-in commands.\n\n");
}
} else if (!local_pending_command && argv[optind]) {
//printf( "optind=%d argv[optind]='%s'\n", optind, argv[optind]);
input = bb_xfopen(argv[optind], "r");
/* be lazy, never mark this closed */
@ -1614,15 +1616,10 @@ int lash_main(int argc_l, char **argv_l)
if (!cwd)
cwd = bb_msg_unknown;
#ifdef CONFIG_FEATURE_CLEAN_UP
atexit(free_memory);
#endif
if (ENABLE_FEATURE_CLEAN_UP) atexit(free_memory);
#ifdef CONFIG_FEATURE_COMMAND_EDITING
cmdedit_set_initial_prompt();
#else
PS1 = NULL;
#endif
if (ENABLE_FEATURE_COMMAND_EDITING) cmdedit_set_initial_prompt();
else PS1 = NULL;
return (busy_loop(input));
}