Exit if --no-execute is enabled don't interactively read from the terminal

Don't go into implicit interactive mode without ever executing
anything - not even `exit` or reacting to ctrl-d. That just renders
the shell useless and unquittable.
This commit is contained in:
Fabian Homborg 2021-01-01 21:15:09 +01:00
parent eb43fc83c5
commit cf8219e3ce
3 changed files with 10 additions and 0 deletions

View File

@ -503,6 +503,10 @@ int main(int argc, char **argv) {
parser.libdata().exit_current_script = false;
} else if (my_optind == argc) {
// Implicitly interactive mode.
if (opts.no_exec && isatty(STDIN_FILENO)) {
FLOGF(error, L"no-execute mode enabled and no script given. Exiting");
return EXIT_FAILURE; // above line should always exit
}
res = reader_read(parser, STDIN_FILENO, {});
} else {
const char *file = *(argv + (my_optind++));

View File

@ -53,3 +53,6 @@ $fish -c 'string escape y$argv' -c 'string escape x$argv' 1 2 3
# CHECK: x1
# CHECK: x2
# CHECK: x3
# Should just do nothing.
$fish --no-execute

View File

@ -51,5 +51,8 @@ expect_prompt("hoge")
sendline("echo hoge >| \n cat")
expect_prompt("hoge")
sendline("$fish --no-execute 2>&1")
expect_prompt("error: no-execute mode enabled and no script given. Exiting")
sendline("source; or echo failed")
expect_prompt("failed")