91692f1
From 4d2e315490b778707b3a3afdfc514d5083a97a11 Mon Sep 17 00:00:00 2001
91692f1
From: Chet Ramey <chet.ramey@case.edu>
91692f1
Date: Fri, 18 Jan 2019 15:12:37 -0500
91692f1
Subject: [PATCH] Bash-5.0 patch 1: fix pathname expansion of directory names
91692f1
 containing backslashes
91692f1
91692f1
---
91692f1
 bashline.c           | 62 +++++++++++++++++++++++++++++++++++++++++---
91692f1
 lib/glob/glob_loop.c |  6 -----
91692f1
 patchlevel.h         |  2 +-
91692f1
 3 files changed, 60 insertions(+), 10 deletions(-)
91692f1
91692f1
diff --git a/bashline.c b/bashline.c
91692f1
index 2846aabf..75e79f1a 100644
91692f1
--- a/bashline.c
91692f1
+++ b/bashline.c
91692f1
@@ -231,6 +231,7 @@ static int bash_possible_variable_completions __P((int, int));
91692f1
 static int bash_complete_command __P((int, int));
91692f1
 static int bash_possible_command_completions __P((int, int));
91692f1
 
91692f1
+static int completion_glob_pattern __P((char *));
91692f1
 static char *glob_complete_word __P((const char *, int));
91692f1
 static int bash_glob_completion_internal __P((int));
91692f1
 static int bash_glob_complete_word __P((int, int));
91692f1
@@ -1741,7 +1742,7 @@ bash_default_completion (text, start, end, qc, compflags)
91692f1
 
91692f1
   /* This could be a globbing pattern, so try to expand it using pathname
91692f1
      expansion. */
91692f1
-  if (!matches && glob_pattern_p (text))
91692f1
+  if (!matches && completion_glob_pattern ((char *)text))
91692f1
     {
91692f1
       matches = rl_completion_matches (text, glob_complete_word);
91692f1
       /* A glob expression that matches more than one filename is problematic.
91692f1
@@ -1850,7 +1851,7 @@ command_word_completion_function (hint_text, state)
91692f1
 	  glob_matches = (char **)NULL;
91692f1
 	}
91692f1
 
91692f1
-      globpat = glob_pattern_p (hint_text);
91692f1
+      globpat = completion_glob_pattern ((char *)hint_text);
91692f1
 
91692f1
       /* If this is an absolute program name, do not check it against
91692f1
 	 aliases, reserved words, functions or builtins.  We must check
91692f1
@@ -3713,6 +3714,61 @@ bash_complete_command_internal (what_to_do)
91692f1
   return bash_specific_completion (what_to_do, command_word_completion_function);
91692f1
 }
91692f1
 
91692f1
+static int
91692f1
+completion_glob_pattern (string)
91692f1
+     char *string;
91692f1
+{
91692f1
+  register int c;
91692f1
+  char *send;
91692f1
+  int open;
91692f1
+
91692f1
+  DECLARE_MBSTATE;
91692f1
+
91692f1
+  open = 0;
91692f1
+  send = string + strlen (string);
91692f1
+
91692f1
+  while (c = *string++)
91692f1
+    {
91692f1
+      switch (c)
91692f1
+	{
91692f1
+	case '?':
91692f1
+	case '*':
91692f1
+	  return (1);
91692f1
+
91692f1
+	case '[':
91692f1
+	  open++;
91692f1
+	  continue;
91692f1
+
91692f1
+	case ']':
91692f1
+	  if (open)
91692f1
+	    return (1);
91692f1
+	  continue;
91692f1
+
91692f1
+	case '+':
91692f1
+	case '@':
91692f1
+	case '!':
91692f1
+	  if (*string == '(')	/*)*/
91692f1
+	    return (1);
91692f1
+	  continue;
91692f1
+
91692f1
+	case '\\':
91692f1
+	  if (*string == 0)
91692f1
+	    return (0);	 	  
91692f1
+	}
91692f1
+
91692f1
+      /* Advance one fewer byte than an entire multibyte character to
91692f1
+	 account for the auto-increment in the loop above. */
91692f1
+#ifdef HANDLE_MULTIBYTE
91692f1
+      string--;
91692f1
+      ADVANCE_CHAR_P (string, send - string);
91692f1
+      string++;
91692f1
+#else
91692f1
+      ADVANCE_CHAR_P (string, send - string);
91692f1
+#endif
91692f1
+    }
91692f1
+  return (0);
91692f1
+}
91692f1
+
91692f1
 static char *globtext;
91692f1
 static char *globorig;
91692f1
 
91692f1
@@ -3877,7 +3933,7 @@ bash_vi_complete (count, key)
91692f1
       t = substring (rl_line_buffer, p, rl_point);
91692f1
     }      
91692f1
 
91692f1
-  if (t && glob_pattern_p (t) == 0)
91692f1
+  if (t && completion_glob_pattern (t) == 0)
91692f1
     rl_explicit_arg = 1;	/* XXX - force glob_complete_word to append `*' */
91692f1
   FREE (t);
91692f1
 
91692f1
diff --git a/lib/glob/glob_loop.c b/lib/glob/glob_loop.c
91692f1
index 5f319cc2..7d6ae211 100644
91692f1
--- a/lib/glob/glob_loop.c
91692f1
+++ b/lib/glob/glob_loop.c
91692f1
@@ -54,17 +54,11 @@ INTERNAL_GLOB_PATTERN_P (pattern)
91692f1
 	continue;
91692f1
 
91692f1
       case L('\\'):
91692f1
-#if 0
91692f1
 	/* Don't let the pattern end in a backslash (GMATCH returns no match
91692f1
 	   if the pattern ends in a backslash anyway), but otherwise return 1,
91692f1
 	   since the matching engine uses backslash as an escape character
91692f1
 	   and it can be removed. */
91692f1
 	return (*p != L('\0'));
91692f1
-#else
91692f1
-	/* The pattern may not end with a backslash. */
91692f1
-	if (*p++ == L('\0'))
91692f1
-	  return 0;
91692f1
-#endif
91692f1
       }
91692f1
 
91692f1
   return 0;
91692f1
diff --git a/patchlevel.h b/patchlevel.h
91692f1
index 1cd7c96c..40db1a32 100644
91692f1
--- a/patchlevel.h
91692f1
+++ b/patchlevel.h
91692f1
@@ -25,6 +25,6 @@
91692f1
    regexp `^#define[ 	]*PATCHLEVEL', since that's what support/mkversion.sh
91692f1
    looks for to find the patch level (for the sccs version string). */
91692f1
 
91692f1
-#define PATCHLEVEL 0
91692f1
+#define PATCHLEVEL 1
91692f1
 
91692f1
 #endif /* _PATCHLEVEL_H_ */
91692f1
-- 
91692f1
2.17.2
91692f1