From ede7124fd45e52b5eb66d04756a29703e8a537c6 Mon Sep 17 00:00:00 2001 From: Chet Ramey Date: Wed, 22 Feb 2023 09:36:28 -0500 Subject: [PATCH] fix for EOF while reading a quoted string; allow window size updates during trap commands or `bind -x' commands --- CWRU/CWRU.chlog | 19 +++++++++++++++++++ builtins/evalfile.c | 4 +++- jobs.c | 12 ++++++++++-- parse.y | 24 ++++++++++++++++++++++-- 4 files changed, 54 insertions(+), 5 deletions(-) diff --git a/CWRU/CWRU.chlog b/CWRU/CWRU.chlog index 6fa0ee01..34539b3b 100644 --- a/CWRU/CWRU.chlog +++ b/CWRU/CWRU.chlog @@ -5418,3 +5418,22 @@ parse.y doc/{bash.1,bashref.texi} - update aliases description based on a bug-bash discussion - update description of word splitting behavior when IFS is unset + +builtins/evalfile.c + - _evalfile: if reading the entire file doesn't return the same + number of bytes as requested (the file size), treat this as a read + error + + 2/21 + ---- +parse.y + - yylex: if read_token returns < 0, return YYEOF if EOF_Reached = 1. + Don't return yacc_EOF because that allows commands to be executed. + - grammar: add a production to handle YYEOF, treating it the same as + yacc_EOF. Based on a report from + Eduardo A. Bustamante López + +jobs.c + - wait_for: if we're checking for window size changes, allow checks + during trap commands while readline is active or `bind -x' command + execution. Fix from Koichi Murase diff --git a/builtins/evalfile.c b/builtins/evalfile.c index f694794f..9b6f4215 100644 --- a/builtins/evalfile.c +++ b/builtins/evalfile.c @@ -151,7 +151,7 @@ file_error_and_exit: (*errfunc) (_("%s: file is too large"), filename); close (fd); return ((flags & FEVAL_BUILTIN) ? EXECUTION_FAILURE : -1); - } + } if (S_ISREG (finfo.st_mode) && file_size <= SSIZE_MAX) { @@ -159,6 +159,8 @@ file_error_and_exit: nr = read (fd, string, file_size); if (nr >= 0) string[nr] = '\0'; + if (nr != file_size) + nr = -1; /* XXX - didn't get the whole file */ } else nr = zmapfd (fd, &string, 0); diff --git a/jobs.c b/jobs.c index d6552a3e..c0cae92d 100644 --- a/jobs.c +++ b/jobs.c @@ -3058,8 +3058,16 @@ if (job == NO_JOB) else #if defined (READLINE) /* We don't want to do this if we are running a process during - programmable completion or a command bound to `bind -x'. */ - if (RL_ISSTATE (RL_STATE_COMPLETING|RL_STATE_DISPATCHING|RL_STATE_TERMPREPPED) == 0) + programmable completion, but we do want to handle window size + changes for traps while readline is active or a command bound + to `bind -x'. */ + if (RL_ISSTATE (RL_STATE_COMPLETING) == 0) + if (RL_ISSTATE(RL_STATE_DISPATCHING|RL_STATE_TERMPREPPED) != 0) + { + if (check_window_size) + get_new_window_size (0, (int *)0, (int *)0); + } + else #endif get_tty_state (); diff --git a/parse.y b/parse.y index 94a42699..2bfc0c66 100644 --- a/parse.y +++ b/parse.y @@ -466,6 +466,21 @@ inputunit: simple_list simple_list_terminator YYABORT; } } + | error YYEOF + { + global_command = (COMMAND *)NULL; + if (last_command_exit_value == 0) + last_command_exit_value = EX_BADUSAGE; /* force error return */ + if (interactive && parse_and_execute_level == 0) + { + handle_eof_input_unit (); + YYACCEPT; + } + else + { + YYABORT; + } + } | yacc_EOF { /* Case of EOF seen by itself. Do ignoreeof or @@ -2459,6 +2474,11 @@ shell_getc (int remove_quoted_newline) /* If we want to make read errors cancel execution of any partial line, take out the checks for i == 0 above and set i = 0 if shell_input_line_terminator == READERR. */ + /* XXX TAG: bash-5.3 austingroup interp 1629 */ +#if defined (FATAL_READERROR) + if (shell_input_line_terminator == READERR) + i = 0; /* no-op for now */ +#endif shell_input_line[i] = '\0'; break; @@ -2923,9 +2943,9 @@ yylex (void) if (current_token < 0) #if defined (YYERRCODE) && !defined (YYUNDEF) - current_token = YYERRCODE; + current_token = EOF_Reached ? YYEOF : YYERRCODE; #else - current_token = YYUNDEF; + current_token = EOF_Reached ? YYEOF : YYUNDEF; #endif return (current_token);