From 55a83114200b86faf1dacffed036d7ea14d22b3f Mon Sep 17 00:00:00 2001 From: Chet Ramey Date: Tue, 11 Oct 2022 16:17:22 -0400 Subject: [PATCH] fix for line numbers for nested function declarations; fix execve error for ENOENT --- CWRU/CWRU.chlog | 16 ++++++++++++++++ execute_cmd.c | 18 +++++++++++------- jobs.c | 1 - lib/glob/sm_loop.c | 2 ++ lib/glob/smatch.c | 5 +++++ parse.y | 12 ++++++++---- 6 files changed, 42 insertions(+), 12 deletions(-) diff --git a/CWRU/CWRU.chlog b/CWRU/CWRU.chlog index d2f2b8ad..b04fb256 100644 --- a/CWRU/CWRU.chlog +++ b/CWRU/CWRU.chlog @@ -4062,3 +4062,19 @@ parse.y execute_cmd.c - execute_cond_node: reset extended_glob to the value of extglob_flag, since we're executing a command here + + 10/8 + ---- +parse.y + - save_dstart: when we set the value of function_dstart, save the old + value in save_dstart (read_token, read_token_word); restore it in + the grammar production after calling make_function_def. This gives + you correct line numbers for one level of function nesting. + Report from Daniel Castro + + 10/10 + ----- +execute_cmd.c + - shell_execve: rearrange code so that we check for a bad interpreter + before printing a generic ENOENT error message. Report from + Kirill Elagin diff --git a/execute_cmd.c b/execute_cmd.c index a37890ab..abb19b73 100644 --- a/execute_cmd.c +++ b/execute_cmd.c @@ -5983,11 +5983,6 @@ shell_execve (command, args, env) errno = i; file_error (command); } - else if (i == ENOENT) - { - errno = i; - internal_error (_("%s: cannot execute: required file not found"), command); - } else { /* The file has the execute bits set, but the kernel refuses to @@ -6015,9 +6010,18 @@ shell_execve (command, args, env) FREE (interp); return (EX_NOEXEC); } + else #endif - errno = i; - file_error (command); + if (i == ENOENT) + { + errno = i; + internal_error (_("%s: cannot execute: required file not found"), command); + } + else + { + errno = i; + file_error (command); + } } return (last_command_exit_value); } diff --git a/jobs.c b/jobs.c index f7112627..4dde9892 100644 --- a/jobs.c +++ b/jobs.c @@ -4338,7 +4338,6 @@ notify_of_job_status () if (termsig && WIFSIGNALED (s) && termsig != SIGINT && termsig != SIGPIPE) #endif { -itrace("notify_of_job_status: printing status of foreground job %d", job); fprintf (stderr, "%s", j_strsignal (termsig)); if (WIFCORED (s)) diff --git a/lib/glob/sm_loop.c b/lib/glob/sm_loop.c index 247ba28a..592a78db 100644 --- a/lib/glob/sm_loop.c +++ b/lib/glob/sm_loop.c @@ -846,6 +846,8 @@ fprintf(stderr, "extmatch: flags = %d\n", flags); case, we just want to compare the two as strings. */ return (STRCOMPARE (p - 1, pe, s, se)); + glob_recursion_depth++; + switch (xc) { case L('+'): /* match one or more occurrences */ diff --git a/lib/glob/smatch.c b/lib/glob/smatch.c index 379c2d2e..a40b9e5e 100644 --- a/lib/glob/smatch.c +++ b/lib/glob/smatch.c @@ -60,6 +60,7 @@ extern int fnmatch (const char *, const char *, int); #endif int glob_asciirange = GLOBASCII_DEFAULT; +int glob_recursion_depth; #if FNMATCH_EQUIV_FALLBACK /* Construct a string w1 = "c1" and a pattern w2 = "[[=c2=]]" and pass them @@ -609,6 +610,8 @@ xstrmatch (pattern, string, flags) wchar_t *wpattern, *wstring; size_t plen, slen, mplen, mslen; + glob_recursion_depth = 0; + if (MB_CUR_MAX == 1) return (internal_strmatch ((unsigned char *)pattern, (unsigned char *)string, flags)); @@ -633,6 +636,8 @@ xstrmatch (pattern, string, flags) return ret; #else + glob_recursion_depth = 0; + return (internal_strmatch ((unsigned char *)pattern, (unsigned char *)string, flags)); #endif /* !HANDLE_MULTIBYTE */ } diff --git a/parse.y b/parse.y index 817ae24b..75904eea 100644 --- a/parse.y +++ b/parse.y @@ -291,9 +291,11 @@ static int shell_input_line_terminator; /* The line number in a script on which a function definition starts. */ static int function_dstart; +static int save_dstart = -1; /* The line number in a script on which a function body starts. */ static int function_bstart; +static int save_bstart = -1; /* The line number in a script at which an arithmetic for command starts. */ static int arith_for_lineno; @@ -945,13 +947,13 @@ case_command: CASE WORD newline_list IN newline_list ESAC ; function_def: WORD '(' ')' newline_list function_body - { $$ = make_function_def ($1, $5, function_dstart, function_bstart); } + { $$ = make_function_def ($1, $5, function_dstart, function_bstart); function_dstart = save_dstart; } | FUNCTION WORD '(' ')' newline_list function_body - { $$ = make_function_def ($2, $6, function_dstart, function_bstart); } + { $$ = make_function_def ($2, $6, function_dstart, function_bstart); function_dstart = save_dstart; } | FUNCTION WORD function_body - { $$ = make_function_def ($2, $3, function_dstart, function_bstart); } + { $$ = make_function_def ($2, $3, function_dstart, function_bstart); function_dstart = save_dstart; } | FUNCTION WORD '\n' newline_list function_body - { $$ = make_function_def ($2, $5, function_dstart, function_bstart); } + { $$ = make_function_def ($2, $5, function_dstart, function_bstart); function_dstart = save_dstart; } ; function_body: shell_command @@ -3557,6 +3559,7 @@ read_token (command) #if defined (ALIAS) parser_state &= ~PST_ALEXPNEXT; #endif /* ALIAS */ + save_dstart = function_dstart; function_dstart = line_number; } @@ -5319,6 +5322,7 @@ got_token: { case FUNCTION: parser_state |= PST_ALLOWOPNBRC; + save_dstart = function_dstart; function_dstart = line_number; break; case CASE: