diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2022-10-27 10:38:25 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2022-10-27 10:45:05 +0200 |
commit | 70e0885229d250c2c4dede0a9513c76c10ad44bd (patch) | |
tree | ca789d2a20775f1d31ef637d7794c96acfa76362 | |
parent | e6a09861b9a76b5527aa1310cff3d4e772b292b8 (diff) | |
download | barebox-70e0885229d250c2c4dede0a9513c76c10ad44bd.tar.gz barebox-70e0885229d250c2c4dede0a9513c76c10ad44bd.tar.xz |
hush: Fix handling '\ '
Currently when doing:
echo foo\ bar
we will get argv[1] = "foo\" and argv[2] = "bar".
An unquoted escaped whitespace should be replaced by a whitespace.
With this the above will correctly result in argv[1] = "foo bar"
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r-- | common/hush.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/common/hush.c b/common/hush.c index 6a089fabf1..5138a1a45a 100644 --- a/common/hush.c +++ b/common/hush.c @@ -617,6 +617,7 @@ static int builtin_exit(struct p_context *ctx, struct child_prog *child, static void remove_quotes_in_str(char *src) { char *trg = src; + bool in_double_quotes = false; while (*src) { if (*src == '\'') { @@ -629,6 +630,7 @@ static void remove_quotes_in_str(char *src) /* drop quotes */ if (*src == '"') { + in_double_quotes = !in_double_quotes; src++; continue; } @@ -654,6 +656,13 @@ static void remove_quotes_in_str(char *src) continue; } + /* replace '\ ' with ' ' */ + if (!in_double_quotes && *src == '\\' && *(src + 1) == ' ') { + *trg++ = ' '; + src += 2; + continue; + } + *trg++ = *src++; } *trg = 0; |