]> git.ipfire.org Git - thirdparty/bash.git/commitdiff
Bash-5.0 patch 2: fix expansion of aliases whose value ends with an unquoted tab
authorChet Ramey <chet.ramey@case.edu>
Fri, 18 Jan 2019 20:13:57 +0000 (15:13 -0500)
committerChet Ramey <chet.ramey@case.edu>
Fri, 18 Jan 2019 20:13:57 +0000 (15:13 -0500)
parse.y
parser.h
patchlevel.h
y.tab.c

diff --git a/parse.y b/parse.y
index 3ff87bccc06c1f9ace9cdf2d0dd02ab506e36f9c..07e6e3e44a9a87c8103ad0415b1d3384ae5066e7 100644 (file)
--- a/parse.y
+++ b/parse.y
@@ -2557,12 +2557,14 @@ next_alias_char:
   if (uc == 0 && pushed_string_list && pushed_string_list->flags != PSH_SOURCE &&
       pushed_string_list->flags != PSH_DPAREN &&
       (parser_state & PST_COMMENT) == 0 &&
+      (parser_state & PST_ENDALIAS) == 0 &&    /* only once */
       shell_input_line_index > 0 &&
-      shell_input_line[shell_input_line_index-1] != ' ' &&
+      shellblank (shell_input_line[shell_input_line_index-1]) == 0 &&
       shell_input_line[shell_input_line_index-1] != '\n' &&
       shellmeta (shell_input_line[shell_input_line_index-1]) == 0 &&
       (current_delimiter (dstack) != '\'' && current_delimiter (dstack) != '"'))
     {
+      parser_state |= PST_ENDALIAS;
       return ' ';      /* END_ALIAS */
     }
 #endif
@@ -2571,6 +2573,7 @@ pop_alias:
   /* This case works for PSH_DPAREN as well */
   if (uc == 0 && pushed_string_list && pushed_string_list->flags != PSH_SOURCE)
     {
+      parser_state &= ~PST_ENDALIAS;
       pop_string ();
       uc = shell_input_line[shell_input_line_index];
       if (uc)
index 54dd2c889850b552d2cb75ffd52fb55d56b44bcb..6d08915d32018c39992ba0205cd598cf7b0d24fb 100644 (file)
--- a/parser.h
+++ b/parser.h
@@ -47,6 +47,7 @@
 #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 */
+#define PST_ENDALIAS   0x200000        /* just finished expanding and consuming an alias */
 
 /* Definition of the delimiter stack.  Needed by parse.y and bashhist.c. */
 struct dstack {
index 40db1a32c9677acffd4d334ffefd062242f730ba..a988d852644985230969d343fdc0c88a3626f7a4 100644 (file)
@@ -25,6 +25,6 @@
    regexp `^#define[   ]*PATCHLEVEL', since that's what support/mkversion.sh
    looks for to find the patch level (for the sccs version string). */
 
-#define PATCHLEVEL 1
+#define PATCHLEVEL 2
 
 #endif /* _PATCHLEVEL_H_ */
diff --git a/y.tab.c b/y.tab.c
index 1abe2c505c3f4572c2233756f0d04f554c8d4883..7efce3c8c823cb5d59ed504872cf2ed9d4714fb2 100644 (file)
--- a/y.tab.c
+++ b/y.tab.c
@@ -4873,12 +4873,14 @@ next_alias_char:
   if (uc == 0 && pushed_string_list && pushed_string_list->flags != PSH_SOURCE &&
       pushed_string_list->flags != PSH_DPAREN &&
       (parser_state & PST_COMMENT) == 0 &&
+      (parser_state & PST_ENDALIAS) == 0 &&    /* only once */
       shell_input_line_index > 0 &&
-      shell_input_line[shell_input_line_index-1] != ' ' &&
+      shellblank (shell_input_line[shell_input_line_index-1]) == 0 &&
       shell_input_line[shell_input_line_index-1] != '\n' &&
       shellmeta (shell_input_line[shell_input_line_index-1]) == 0 &&
       (current_delimiter (dstack) != '\'' && current_delimiter (dstack) != '"'))
     {
+      parser_state |= PST_ENDALIAS;
       return ' ';      /* END_ALIAS */
     }
 #endif
@@ -4887,6 +4889,7 @@ pop_alias:
   /* This case works for PSH_DPAREN as well */
   if (uc == 0 && pushed_string_list && pushed_string_list->flags != PSH_SOURCE)
     {
+      parser_state &= ~PST_ENDALIAS;
       pop_string ();
       uc = shell_input_line[shell_input_line_index];
       if (uc)