]> git.ipfire.org Git - thirdparty/bash.git/commitdiff
commit bash-20181226 snapshot
authorChet Ramey <chet.ramey@case.edu>
Thu, 3 Jan 2019 15:19:09 +0000 (10:19 -0500)
committerChet Ramey <chet.ramey@case.edu>
Thu, 3 Jan 2019 15:19:09 +0000 (10:19 -0500)
16 files changed:
CWRU/CWRU.chlog
MANIFEST
builtins/evalstring.c
examples/loadables/basename.c
examples/loadables/dirname.c
examples/loadables/mkdir.c
lib/glob/glob_loop.c
parse.y
parser.h
tests/alias4.sub
tests/errors.right
tests/errors.tests
tests/errors8.sub [new file with mode: 0644]
tests/glob.right
tests/glob.tests
tests/glob4.sub [new file with mode: 0644]

index b407ae9ef09f35a677cdfb919aa66f6067747052..f05d6204bcc9decdeb146af3e4a3104eb6a6e14b 100644 (file)
@@ -3604,7 +3604,7 @@ pathexp.c
          does not end in a backslash, we need to return true. Fixes bug
          reported by Robert Elz <kre@bmunnari.OZ.AU>
 
-lib/glob/gm_loop.c
+lib/glob/glob_loop.c
        - INTERNAL_GLOB_PATTERN_P: same change to return TRUE for a backslash
          that doesn't end the pattern
 
@@ -4925,3 +4925,41 @@ subst.c
          tilde expansion at all, even for the previously-special-case array
          subscript expansion. Report from Bize Ma <binaryzebra@gmail.com>
        - expand_word_internal: take out Q_ARRAYSUB check for tilde expansion
+
+                                  12/26
+                                  -----
+builtins/evalstring.c
+       - parse_and_execute: if the eval builtin gets a parser error while
+         parsing a  string in posix mode, don't exit the shell if the eval
+         was run by the command builtin. report from Martijn Dekker
+         <martijn@inlv.org>
+
+examples/loadables/{basename,dirname}.c
+       - dirname_builtin: skip over any `--' ending the options.  Report from
+         Peng Yu <pengyu.ut@gmail.com>
+
+                                  12/27
+                                  -----
+examples/loadables/mkdir.c
+       - make_path: add argument noting whether or not the user specified -m;
+         only attempt the chmod on an existing directory if the user did so
+       - make_path: when creating intermediate directories, perform the
+         mkdir (path, 0) and chmod separately as the posix text recommends
+
+                                  12/28
+                                  -----
+parser.h
+       - PST_COMMENT: new state, set when the shell is reading characters
+         until newline as part of comment processing
+
+parse.y
+       - shell_getc: don't return a space at the end of a token if the parser
+         is consuming a comment. Fixes bug reported by Harald van Dijk
+         <harald@gigawatt.nl>
+
+                                  12/31
+                                  -----
+lib/glob/glob_loop.c
+       - INTERNAL_GLOB_PATTERN_P: revert change from 4/27 that makes this
+         function return non-zero for a backslash in the string. Based on a
+         report from Tom Ryder <tom@sanctum.geek.nz>
index 44996811a595c620021447d1f0cc1735e2963c64..03de22102cec16243069922800f0a783a10cdbf3 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -990,6 +990,7 @@ tests/errors4.sub   f
 tests/errors5.sub      f
 tests/errors6.sub      f
 tests/errors7.sub      f
+tests/errors8.sub      f
 tests/execscript       f
 tests/exec.right       f
 tests/exec1.sub                f       755
@@ -1058,6 +1059,7 @@ tests/glob.tests  f
 tests/glob1.sub                f
 tests/glob2.sub                f
 tests/glob3.sub                f
+tests/glob4.sub                f
 tests/glob.right       f
 tests/globstar.tests   f
 tests/globstar.right   f
index 5073ca49aa4c789b23bb11fd1059d961d73b6618..1496eeec2c01e7fa01c14bf4f965e0a20a964268 100644 (file)
@@ -448,11 +448,11 @@ parse_and_execute (string, from_file, flags)
        }
       else
        {
-         last_result = EXECUTION_FAILURE;
+         last_result = EX_BADUSAGE;    /* was EXECUTION_FAILURE */
 
          if (interactive_shell == 0 && this_shell_builtin &&
              (this_shell_builtin == source_builtin || this_shell_builtin == eval_builtin) &&
-             last_command_exit_value == EX_BADSYNTAX && posixly_correct)
+             last_command_exit_value == EX_BADSYNTAX && posixly_correct && executing_command_builtin == 0)
            {
              should_jump_to_top_level = 1;
              code = ERREXIT;
index 3ca1844182be98e13964b28b6c37a19ef91e5eaa..8ebdff4f7809e02825dc59b308a2721da5b6639e 100644 (file)
@@ -46,6 +46,7 @@ basename_builtin (list)
 
   if (no_options (list))
     return (EX_USAGE);
+  list = loptend;
 
   string = list->word->word;
   suffix = (char *)NULL;
index 69019cbc37f6703d15211e6bb42790b5cac329ac..d802ca77c116464c71661a83e380e21bba1e7157 100644 (file)
@@ -30,6 +30,7 @@
 #include "builtins.h"
 #include "shell.h"
 #include "common.h"
+#include "bashgetopt.h"
 
 int
 dirname_builtin (list)
@@ -38,15 +39,16 @@ dirname_builtin (list)
   int slen;
   char *string;
 
+  if (no_options (list))
+    return (EX_USAGE);
+  list = loptend;
+
   if (list == 0 || list->next)
     {
       builtin_usage ();
       return (EX_USAGE);
     }
 
-  if (no_options (list))
-    return (EX_USAGE);
-
   string = list->word->word;
   slen = strlen (string);
 
index 767ad9eb8f418a8ceee6e2be65620b0a692375f5..b38111994350ee6e311e158b2776e971f8632ec5 100644 (file)
@@ -52,12 +52,12 @@ int
 mkdir_builtin (list)
      WORD_LIST *list;
 {
-  int opt, pflag, omode, rval, nmode, parent_mode;
+  int opt, pflag, mflag, omode, rval, nmode, parent_mode;
   char *mode;
   WORD_LIST *l;
 
   reset_internal_getopt ();
-  pflag = 0;
+  pflag = mflag = 0;
   mode = (char *)NULL;
   while ((opt = internal_getopt(list, "m:p")) != -1)
     switch (opt)
@@ -66,6 +66,7 @@ mkdir_builtin (list)
          pflag = 1;
          break;
        case 'm':
+         mflag = 1;
          mode = list_optarg;
          break;
        CASE_HELPOPT;
@@ -115,7 +116,7 @@ mkdir_builtin (list)
 
   for (rval = EXECUTION_SUCCESS, l = list; l; l = l->next)
     {
-      if (pflag && make_path (l->word->word, nmode, parent_mode))
+      if (pflag && make_path (l->word->word, mflag, nmode, parent_mode))
        {
          rval = EXECUTION_FAILURE;
          continue;
@@ -133,8 +134,9 @@ mkdir_builtin (list)
    this changes the process's umask; make sure that all paths leading to a
    return reset it to ORIGINAL_UMASK */
 static int
-make_path (path, nmode, parent_mode)
+make_path (path, user_mode, nmode, parent_mode)
      char *path;
+     int user_mode;
      int nmode, parent_mode;
 {
   int oumask;
@@ -149,7 +151,7 @@ make_path (path, nmode, parent_mode)
          return 1;
        }
        
-      if (chmod (path, nmode))
+      if (user_mode && chmod (path, nmode))
         {
           builtin_error ("%s: %s", path, strerror (errno));
           return 1;
@@ -173,13 +175,20 @@ make_path (path, nmode, parent_mode)
       *p = '\0';
       if (stat (npath, &sb) != 0)
        {
-         if (mkdir (npath, parent_mode))
+         if (mkdir (npath, 0))
            {
              builtin_error ("cannot create directory `%s': %s", npath, strerror (errno));
              umask (original_umask);
              free (npath);
              return 1;
            }
+         if (chmod (npath, parent_mode) != 0)
+           {
+             builtin_error ("cannot chmod directory `%s': %s", npath, strerror (errno));
+             umask (original_umask);
+             free (npath);
+             return 1;
+           }
        }
       else if (S_ISDIR (sb.st_mode) == 0)
         {
index 7d6ae2113c509ec64a9087b03ce4c04e67b217b9..5f319cc2efa70986c3672b57022fd11a3b9a0492 100644 (file)
@@ -54,11 +54,17 @@ INTERNAL_GLOB_PATTERN_P (pattern)
        continue;
 
       case L('\\'):
+#if 0
        /* Don't let the pattern end in a backslash (GMATCH returns no match
           if the pattern ends in a backslash anyway), but otherwise return 1,
           since the matching engine uses backslash as an escape character
           and it can be removed. */
        return (*p != L('\0'));
+#else
+       /* The pattern may not end with a backslash. */
+       if (*p++ == L('\0'))
+         return 0;
+#endif
       }
 
   return 0;
diff --git a/parse.y b/parse.y
index 3e100fca8fe7540fb733310356c97bdcf169cee3..a431f260620c5db60b13e69a8549df2e1b7e42d4 100644 (file)
--- a/parse.y
+++ b/parse.y
@@ -419,7 +419,10 @@ inputunit: simple_list simple_list_terminator
                             only interesting in non-interactive shells */
                          global_command = (COMMAND *)NULL;
                          if (last_command_exit_value == 0)
+{
+itrace("parser: forcing EX_BADUSAGE; executing_command_builtin = %d", executing_command_builtin);
                            last_command_exit_value = EX_BADUSAGE;      /* force error return */
+}
                          handle_eof_input_unit ();
                          if (interactive && parse_and_execute_level == 0)
                            {
@@ -2552,10 +2555,11 @@ next_alias_char:
      return the space that will delimit the token and postpone the pop_string.
      This set of conditions duplicates what used to be in mk_alexpansion ()
      below, with the addition that we don't add a space if we're currently
-     reading a quoted string. */
+     reading a quoted string or in a shell comment. */
 #ifndef OLD_ALIAS_HACK
   if (uc == 0 && pushed_string_list && pushed_string_list->flags != PSH_SOURCE &&
       pushed_string_list->flags != PSH_DPAREN &&
+      (parser_state & PST_COMMENT) == 0 &&
       shell_input_line_index > 0 &&
       shell_input_line[shell_input_line_index-1] != ' ' &&
       shell_input_line[shell_input_line_index-1] != '\n' &&
@@ -3267,8 +3271,10 @@ itrace("shell_getc: bash_input.location.string = `%s'", bash_input.location.stri
   if MBTEST(character == '#' && (!interactive || interactive_comments))
     {
       /* A comment.  Discard until EOL or EOF, and then return a newline. */
+      parser_state |= PST_COMMENT;
       discard_until ('\n');
       shell_getc (0);
+      parser_state &= ~PST_COMMENT;
       character = '\n';        /* this will take the next if statement and return. */
     }
 
index 88c799d88128ff4f830cacb0f78b35ddef98d16b..54dd2c889850b552d2cb75ffd52fb55d56b44bcb 100644 (file)
--- a/parser.h
+++ b/parser.h
@@ -46,7 +46,7 @@
 #define PST_HEREDOC    0x020000        /* reading body of here-document */
 #define PST_REPARSE    0x040000        /* re-parsing in parse_string_to_word_list */
 #define PST_REDIRLIST  0x080000        /* parsing a list of redirections preceding a simple command name */
-
+#define PST_COMMENT    0x100000        /* parsing a shell comment; used by aliases */
 
 /* Definition of the delimiter stack.  Needed by parse.y and bashhist.c. */
 struct dstack {
index 966b93d1deac75d70f9cd276f3ee233a7036a687..6ea513a17ee0bba3c18c1ed23c7987b653494287 100644 (file)
@@ -59,3 +59,12 @@ unalias -a
 alias e=echo
 eval '</dev/null e ok 3'
 eval 'a=true e ok 4'
+
+alias comment=#
+comment
+
+alias long_comment='# for x in '
+long_comment text after
+
+# comment
+comment foo bar
index 7627450ba8aafe1c79ef64b4802a7390615e6e29..83338ae03deb214a355605634fd64f68ce095cf3 100644 (file)
@@ -183,4 +183,16 @@ echo builtin
 after non-special builtin: 0
 ./errors7.sub: line 12: x: readonly variable
 ./errors7.sub: line 14: x: readonly variable
-./errors.tests: line 281: `!!': not a valid identifier
+./errors8.sub: eval: line 7: syntax error: unexpected end of file
+ok 1
+./errors8.sub: line 8: v: readonly variable
+ok 2
+./errors8.sub: line 9: v: readonly variable
+ok 3
+./errors8.sub: line 11: shift: 12: shift count out of range
+ok 4
+./errors8.sub: line 13: return: can only `return' from a function or sourced script
+ok 5
+./errors8.sub: line 14: set: notanoption: invalid option name
+ok 6
+./errors.tests: line 283: `!!': not a valid identifier
index 4183d024141507b09da79384a5e60e5422a3cd73..e1554cd10e82530fa25ab737f31c1a799185030c 100644 (file)
@@ -273,6 +273,8 @@ THIS_SH="${THIS_SH} -o posix" ${THIS_SH} ./errors6.sub
 ${THIS_SH} ./errors7.sub
 ${THIS_SH} -o posix ./errors7.sub
 
+${THIS_SH} ./errors8.sub
+
 # this must be last!
 # in posix mode, a function name must be a valid identifier
 # this can't go in posix2.tests, since it causes the shell to exit
diff --git a/tests/errors8.sub b/tests/errors8.sub
new file mode 100644 (file)
index 0000000..b65e1ab
--- /dev/null
@@ -0,0 +1,14 @@
+# the start of a set of tests for command keeping special builtins from
+# exiting the shell on failure
+set -o posix
+readonly v
+
+command eval '( ' || echo ok 1
+
+command export v=foo || echo ok 2
+command readonly v=foo || echo ok 3
+
+command shift 12 || echo ok 4
+
+command return 16 || echo ok 5
+command set -o notanoption || echo ok 6
index 83b7bc7a42dae657a5b30090ee6da503c1db5b63..1ead7b61da1d76dd083317b89dc0c09c0a7225b3 100644 (file)
@@ -56,6 +56,11 @@ ok 2
 ok 3
 ok 4
 ok 5
+argv[1] = <a\?>
+a?
+argv[1] = <a\?>
+a?
+aa
 argv[1] = <a>
 argv[2] = <abc>
 argv[3] = <abd>
@@ -70,7 +75,7 @@ argv[2] = <abc>
 argv[3] = <abd>
 argv[4] = <abe>
 tmp/l1 tmp/l2 tmp/*4 tmp/l3
-./glob.tests: line 46: no match: tmp/*4
+./glob.tests: line 47: no match: tmp/*4
 argv[1] = <bdir/>
 argv[1] = <*>
 argv[1] = <a*>
index cfb086fd09208a8cab1f1041da688f927a2e6a98..01913bbe01c96de6974a1687ba3d9e8f84a6a1a0 100644 (file)
@@ -11,6 +11,7 @@ expect()
 ${THIS_SH} ./glob1.sub
 ${THIS_SH} ./glob2.sub
 ${THIS_SH} ./glob3.sub
+${THIS_SH} ./glob4.sub
 
 MYDIR=$PWD     # save where we are
 
diff --git a/tests/glob4.sub b/tests/glob4.sub
new file mode 100644 (file)
index 0000000..378b5a9
--- /dev/null
@@ -0,0 +1,13 @@
+trap "rm 'a?' aa" EXIT
+touch 'a?' aa
+
+set -- a \?; IFS=\\; var=$*;
+recho "$var"
+unset IFS; printf "%s\n" ${var}
+
+var='a\?'
+recho "$var"
+printf "%s\n" ${var}
+
+var='a\a'
+printf "%s\n" ${var}