3cb876b
From f9dc7ff03a5b63d20ce473c1172e29b736dbea28 Mon Sep 17 00:00:00 2001
3cb876b
From: "David Kaspar [Dee'Kej]" <dkaspar@redhat.com>
3cb876b
Date: Wed, 21 Sep 2016 16:51:08 +0200
3cb876b
Subject: [PATCH] CVE-2016-0634: upstream patch imported
3cb876b
3cb876b
---
3cb876b
 parse.y | 20 ++++++++++++++++----
3cb876b
 y.tab.c | 20 ++++++++++++++++----
3cb876b
 2 files changed, 32 insertions(+), 8 deletions(-)
3cb876b
3cb876b
diff --git a/parse.y b/parse.y
3cb876b
index 0a7fcaa..5676ad7 100644
3cb876b
--- a/parse.y
3cb876b
+++ b/parse.y
3cb876b
@@ -5252,7 +5252,7 @@ decode_prompt_string (string)
3cb876b
 #if defined (PROMPT_STRING_DECODE)
3cb876b
   int result_size, result_index;
3cb876b
   int c, n, i;
3cb876b
-  char *temp, octal_string[4];
3cb876b
+  char *temp, *t_host, octal_string[4];
3cb876b
   struct tm *tm;  
3cb876b
   time_t the_time;
3cb876b
   char timebuf[128];
3cb876b
@@ -5400,7 +5400,11 @@ decode_prompt_string (string)
3cb876b
 
3cb876b
 	    case 's':
3cb876b
 	      temp = base_pathname (shell_name);
3cb876b
-	      temp = savestring (temp);
3cb876b
+	      /* Try to quote anything the user can set in the file system */
3cb876b
+	      if (promptvars || posixly_correct)
3cb876b
+		temp = sh_backslash_quote_for_double_quotes (temp);
3cb876b
+	      else
3cb876b
+		temp = savestring (temp);
3cb876b
 	      goto add_string;
3cb876b
 
3cb876b
 	    case 'v':
3cb876b
@@ -5490,9 +5494,17 @@ decode_prompt_string (string)
3cb876b
 
3cb876b
 	    case 'h':
3cb876b
 	    case 'H':
3cb876b
-	      temp = savestring (current_host_name);
3cb876b
-	      if (c == 'h' && (t = (char *)strchr (temp, '.')))
3cb876b
+	      t_host = savestring (current_host_name);
3cb876b
+	      if (c == 'h' && (t = (char *)strchr (t_host, '.')))
3cb876b
 		*t = '\0';
3cb876b
+	      if (promptvars || posixly_correct)
3cb876b
+		/* Make sure that expand_prompt_string is called with a
3cb876b
+		   second argument of Q_DOUBLE_QUOTES if we use this
3cb876b
+		   function here. */
3cb876b
+		temp = sh_backslash_quote_for_double_quotes (t_host);
3cb876b
+	      else
3cb876b
+		temp = savestring (t_host);
3cb876b
+	      free (t_host);
3cb876b
 	      goto add_string;
3cb876b
 
3cb876b
 	    case '#':
3cb876b
diff --git a/y.tab.c b/y.tab.c
3cb876b
index 793daf6..726d0de 100644
3cb876b
--- a/y.tab.c
3cb876b
+++ b/y.tab.c
3cb876b
@@ -7540,7 +7540,7 @@ decode_prompt_string (string)
3cb876b
 #if defined (PROMPT_STRING_DECODE)
3cb876b
   int result_size, result_index;
3cb876b
   int c, n, i;
3cb876b
-  char *temp, octal_string[4];
3cb876b
+  char *temp, *t_host, octal_string[4];
3cb876b
   struct tm *tm;  
3cb876b
   time_t the_time;
3cb876b
   char timebuf[128];
3cb876b
@@ -7688,7 +7688,11 @@ decode_prompt_string (string)
3cb876b
 
3cb876b
 	    case 's':
3cb876b
 	      temp = base_pathname (shell_name);
3cb876b
-	      temp = savestring (temp);
3cb876b
+	      /* Try to quote anything the user can set in the file system */
3cb876b
+	      if (promptvars || posixly_correct)
3cb876b
+		temp = sh_backslash_quote_for_double_quotes (temp);
3cb876b
+	      else
3cb876b
+		temp = savestring (temp);
3cb876b
 	      goto add_string;
3cb876b
 
3cb876b
 	    case 'v':
3cb876b
@@ -7778,9 +7782,17 @@ decode_prompt_string (string)
3cb876b
 
3cb876b
 	    case 'h':
3cb876b
 	    case 'H':
3cb876b
-	      temp = savestring (current_host_name);
3cb876b
-	      if (c == 'h' && (t = (char *)strchr (temp, '.')))
3cb876b
+	      t_host = savestring (current_host_name);
3cb876b
+	      if (c == 'h' && (t = (char *)strchr (t_host, '.')))
3cb876b
 		*t = '\0';
3cb876b
+	      if (promptvars || posixly_correct)
3cb876b
+		/* Make sure that expand_prompt_string is called with a
3cb876b
+		   second argument of Q_DOUBLE_QUOTES if we use this
3cb876b
+		   function here. */
3cb876b
+		temp = sh_backslash_quote_for_double_quotes (t_host);
3cb876b
+	      else
3cb876b
+		temp = savestring (t_host);
3cb876b
+	      free (t_host);
3cb876b
 	      goto add_string;
3cb876b
 
3cb876b
 	    case '#':
3cb876b
-- 
3cb876b
2.7.4
3cb876b