Fix shell double quoting escaping non-special characters.

This bug was reported by Ricardo Grant.
This commit is contained in:
Jonas 'Sortie' Termansen 2021-09-13 20:37:56 +02:00
parent e02b84cb93
commit c2088ae3ee
1 changed files with 26 additions and 0 deletions

26
sh/sh.c
View File

@ -161,6 +161,10 @@ char* token_finalize(const char* token)
}
else
{
if ( escape && double_quote &&
token[i] != '$' && token[i] != '`' &&
token[i] != '"' && token[i] != '\\' )
stringbuf_append_c(&buf, '\\');
stringbuf_append_c(&buf, token[i]);
escape = false;
}
@ -246,6 +250,10 @@ char* token_expand_variables(const char* token)
}
else
{
if ( escape && double_quote &&
token[i] != '$' && token[i] != '`' &&
token[i] != '"' && token[i] != '\\' )
stringbuf_append_c(&buf, '\\');
stringbuf_append_c(&buf, token[i]);
escape = false;
}
@ -299,6 +307,10 @@ bool token_split(void*** out,
}
else
{
if ( escape && double_quote &&
token[index] != '$' && token[index] != '`' &&
token[index] != '"' && token[index] != '\\' )
stringbuf_append_c(&buf, '\\');
stringbuf_append_c(&buf, token[index]);
escape = false;
}
@ -375,6 +387,10 @@ bool token_expand_wildcards(void*** out,
}
else
{
if ( escape && double_quote &&
token[index] != '$' && token[index] != '`' &&
token[index] != '"' && token[index] != '\\' )
stringbuf_append_c(&buf, '\\');
if ( token[index] == '*' )
num_escaped_wildcards++;
stringbuf_append_c(&buf, token[index]);
@ -423,6 +439,10 @@ bool token_expand_wildcards(void*** out,
}
else
{
if ( escape && double_quote &&
token[index] != '$' && token[index] != '`' &&
token[index] != '"' && token[index] != '\\' )
stringbuf_append_c(&buf, '\\');
if ( token[index] == '*' )
num_escaped_wildcards++;
stringbuf_append_c(&buf, token[index]);
@ -681,6 +701,12 @@ enum sh_tokenize_result sh_tokenize(const char* command,
}
else
{
if ( escaped && double_quote &&
command[command_index] != '$' &&
command[command_index] != '`' &&
command[command_index] != '"' &&
command[command_index] != '\\' )
stringbuf_append_c(&buf, '\\');
stringbuf_append_c(&buf, command[command_index]);
command_index++;
escaped = false;