aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-11-16 03:18:46 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2009-11-16 03:18:46 +0100
commitd8389ad76028a536d1869ec163c15fd817dc7b65 (patch)
tree9c38fad7608a9280209745d4ec1fd70d29ff7cca
parent00243b0a1aa7149660e52e748b82a14e5e818150 (diff)
downloadbusybox-w32-d8389ad76028a536d1869ec163c15fd817dc7b65.tar.gz
busybox-w32-d8389ad76028a536d1869ec163c15fd817dc7b65.tar.bz2
busybox-w32-d8389ad76028a536d1869ec163c15fd817dc7b65.zip
hush: fix handling of words with braces. +65 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--shell/hush.c29
-rw-r--r--shell/hush_test/hush-parsing/brace1.right7
-rwxr-xr-xshell/hush_test/hush-parsing/brace1.tests7
3 files changed, 35 insertions, 8 deletions
diff --git a/shell/hush.c b/shell/hush.c
index 6dd6a0d03..235cee9ee 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -2024,6 +2024,7 @@ static int o_glob(o_string *o, int n)
2024 } 2024 }
2025 2025
2026 memset(&globdata, 0, sizeof(globdata)); 2026 memset(&globdata, 0, sizeof(globdata));
2027//TODO: can use GLOB_BRACE | GLOB_TILDE here:
2027 gr = glob(pattern, 0, NULL, &globdata); 2028 gr = glob(pattern, 0, NULL, &globdata);
2028 debug_printf_glob("glob('%s'):%d\n", pattern, gr); 2029 debug_printf_glob("glob('%s'):%d\n", pattern, gr);
2029 if (gr == GLOB_NOSPACE) 2030 if (gr == GLOB_NOSPACE)
@@ -5384,6 +5385,8 @@ static int parse_group(o_string *dest, struct parse_context *ctx,
5384 goto skip; 5385 goto skip;
5385 } 5386 }
5386#endif 5387#endif
5388
5389#if 0 /* Prevented by caller */
5387 if (command->argv /* word [word]{... */ 5390 if (command->argv /* word [word]{... */
5388 || dest->length /* word{... */ 5391 || dest->length /* word{... */
5389 || dest->o_quoted /* ""{... */ 5392 || dest->o_quoted /* ""{... */
@@ -5393,6 +5396,7 @@ static int parse_group(o_string *dest, struct parse_context *ctx,
5393 "syntax error, groups and arglists don't mix\n"); 5396 "syntax error, groups and arglists don't mix\n");
5394 return 1; 5397 return 1;
5395 } 5398 }
5399#endif
5396 5400
5397#if ENABLE_HUSH_FUNCTIONS 5401#if ENABLE_HUSH_FUNCTIONS
5398 skip: 5402 skip:
@@ -5962,10 +5966,24 @@ static struct pipe *parse_stream(char **pstring,
5962 return pi; 5966 return pi;
5963 } 5967 }
5964 nommu_addchr(&ctx.as_string, ch); 5968 nommu_addchr(&ctx.as_string, ch);
5969
5970 next = '\0';
5971 if (ch != '\n')
5972 next = i_peek(input);
5973
5974 is_special = "{}<>;&|()#'" /* special outside of "str" */
5975 "\\$\"" IF_HUSH_TICK("`"); /* always special */
5976 /* Are { and } special here? */
5977 if (ctx.command->argv /* word [word]{... */
5978 || dest.length /* word{... */
5979 || dest.o_quoted /* ""{... */
5980 || (next != ';' && next != ')' && !strchr(G.ifs, next)) /* {word */
5981 ) {
5982 /* They are not special, skip "{}" */
5983 is_special += 2;
5984 }
5985 is_special = strchr(is_special, ch);
5965 is_ifs = strchr(G.ifs, ch); 5986 is_ifs = strchr(G.ifs, ch);
5966 is_special = strchr("<>;&|(){}#'" /* special outside of "str" */
5967 "\\$\"" IF_HUSH_TICK("`") /* always special */
5968 , ch);
5969 5987
5970 if (!is_special && !is_ifs) { /* ordinary char */ 5988 if (!is_special && !is_ifs) { /* ordinary char */
5971 ordinary_char: 5989 ordinary_char:
@@ -6076,11 +6094,6 @@ static struct pipe *parse_stream(char **pstring,
6076 if (is_ifs) 6094 if (is_ifs)
6077 continue; 6095 continue;
6078 6096
6079 next = '\0';
6080 if (ch != '\n') {
6081 next = i_peek(input);
6082 }
6083
6084 /* Catch <, > before deciding whether this word is 6097 /* Catch <, > before deciding whether this word is
6085 * an assignment. a=1 2>z b=2: b=2 is still assignment */ 6098 * an assignment. a=1 2>z b=2: b=2 is still assignment */
6086 switch (ch) { 6099 switch (ch) {
diff --git a/shell/hush_test/hush-parsing/brace1.right b/shell/hush_test/hush-parsing/brace1.right
new file mode 100644
index 000000000..8619f45d3
--- /dev/null
+++ b/shell/hush_test/hush-parsing/brace1.right
@@ -0,0 +1,7 @@
1{abc}
2{
3}
4hush: can't execute '{cmd': No such file or directory
5hush: can't execute '{': No such file or directory
6hush: can't execute '{': No such file or directory
7Done: 127
diff --git a/shell/hush_test/hush-parsing/brace1.tests b/shell/hush_test/hush-parsing/brace1.tests
new file mode 100755
index 000000000..2b45927c0
--- /dev/null
+++ b/shell/hush_test/hush-parsing/brace1.tests
@@ -0,0 +1,7 @@
1echo {abc}
2echo {
3echo }
4{cmd
5""{
6{""
7echo Done: $?