]> git.ipfire.org Git - thirdparty/bash.git/commitdiff
fix for line numbers for nested function declarations; fix execve error for ENOENT
authorChet Ramey <chet.ramey@case.edu>
Tue, 11 Oct 2022 20:17:22 +0000 (16:17 -0400)
committerChet Ramey <chet.ramey@case.edu>
Tue, 11 Oct 2022 20:17:22 +0000 (16:17 -0400)
CWRU/CWRU.chlog
execute_cmd.c
jobs.c
lib/glob/sm_loop.c
lib/glob/smatch.c
parse.y

index d2f2b8ad0be1e4e7af459effe3825cab70dae727..b04fb2566c40e49f7ad2e7197773efe5b7e88a13 100644 (file)
@@ -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 <danicc097@gmail.com>
+
+                                  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 <kirelagin@gmail.com>
index a37890ab37ac9e3fe3a41acfbfebb09388958dc7..abb19b73c96fa9d030995a3d7e9e05242ec4ff78 100644 (file)
@@ -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 f7112627aa0421a17a33e40557109121fdf090ad..4dde9892bee4f32b2afc28e1705e2d6fe642d139 100644 (file)
--- 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))
index 247ba28aa5c0e7fccc3bd328b5fc8f2e5de21889..592a78db73199ff48c1d51e6b96fef2c39451abd 100644 (file)
@@ -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 */
index 379c2d2e62d5e8452706a1b5a4ba5d5f364bf5fc..a40b9e5efd5ccc85cbc600f7f6afb867f1fd0ee0 100644 (file)
@@ -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 817ae24b9f894cbf1089153ba68a5c73b9d5f9a0..75904eeaa0e173e890127f6922c1624cf2faa458 100644 (file)
--- 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: