You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
2.7 KiB

diff --git a/parse.y b/parse.y
index 12d6def..d4a93a2 100644
--- a/parse.y
+++ b/parse.y
@@ -5103,7 +5103,7 @@ decode_prompt_string (string)
size_t result_size;
int result_index;
int c, n, i;
- char *temp, octal_string[4];
+ char *temp, *t_host, octal_string[4];
struct tm *tm;
time_t the_time;
char timebuf[128];
@@ -5251,7 +5251,11 @@ decode_prompt_string (string)
case 's':
temp = base_pathname (shell_name);
- temp = savestring (temp);
+ /* Try to quote anything the user can set in the file system */
+ if (promptvars || posixly_correct)
+ temp = sh_backslash_quote_for_double_quotes (temp);
+ else
+ temp = savestring (temp);
goto add_string;
case 'v':
@@ -5337,9 +5341,17 @@ decode_prompt_string (string)
case 'h':
case 'H':
- temp = savestring (current_host_name);
- if (c == 'h' && (t = (char *)strchr (temp, '.')))
+ t_host = savestring (current_host_name);
+ if (c == 'h' && (t = (char *)strchr (t_host, '.')))
*t = '\0';
+ if (promptvars || posixly_correct)
+ /* Make sure that expand_prompt_string is called with a
+ second argument of Q_DOUBLE_QUOTES if we use this
+ function here. */
+ temp = sh_backslash_quote_for_double_quotes (t_host);
+ else
+ temp = savestring (t_host);
+ free (t_host);
goto add_string;
case '#':
diff --git a/y.tab.c b/y.tab.c
index 23b88bc..1c0f5a1 100644
--- a/y.tab.c
+++ b/y.tab.c
@@ -7368,7 +7368,7 @@ decode_prompt_string (string)
size_t result_size;
int result_index;
int c, n, i;
- char *temp, octal_string[4];
+ char *temp, *t_host, octal_string[4];
struct tm *tm;
time_t the_time;
char timebuf[128];
@@ -7513,7 +7513,11 @@ decode_prompt_string (string)
case 's':
temp = base_pathname (shell_name);
- temp = savestring (temp);
+ /* Try to quote anything the user can set in the file system */
+ if (promptvars || posixly_correct)
+ temp = sh_backslash_quote_for_double_quotes (temp);
+ else
+ temp = savestring (temp);
goto add_string;
case 'v':
@@ -7599,9 +7603,17 @@ decode_prompt_string (string)
case 'h':
case 'H':
- temp = savestring (current_host_name);
- if (c == 'h' && (t = (char *)strchr (temp, '.')))
+ t_host = savestring (current_host_name);
+ if (c == 'h' && (t = (char *)strchr (t_host, '.')))
*t = '\0';
+ if (promptvars || posixly_correct)
+ /* Make sure that expand_prompt_string is called with a
+ second argument of Q_DOUBLE_QUOTES if we use this
+ function here. */
+ temp = sh_backslash_quote_for_double_quotes (t_host);
+ else
+ temp = savestring (t_host);
+ free (t_host);
goto add_string;
case '#':
--
2.9.3