aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2025-08-14 16:19:58 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2025-08-14 16:19:58 +0200
commit6cc338010515ec4caef802a70f9f374cf98b8294 (patch)
tree658af62d1b336265028e1edde837eed0ec328c4f /shell
parentcad5a79bd4e8ceef4a68f1551fd2b25122bcb1c8 (diff)
downloadbusybox-w32-6cc338010515ec4caef802a70f9f374cf98b8294.tar.gz
busybox-w32-6cc338010515ec4caef802a70f9f374cf98b8294.tar.bz2
busybox-w32-6cc338010515ec4caef802a70f9f374cf98b8294.zip
hush: undo incorrect change which allows a'b'=c to be assignment
While at it, remove now-unused WORD_IS_KEYWORD Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
-rw-r--r--shell/ash_test/ash-misc/assignment2.right2
-rwxr-xr-xshell/ash_test/ash-misc/assignment2.tests2
-rw-r--r--shell/hush.c34
-rw-r--r--shell/hush_test/hush-misc/assignment2.right2
-rwxr-xr-xshell/hush_test/hush-misc/assignment2.tests2
5 files changed, 20 insertions, 22 deletions
diff --git a/shell/ash_test/ash-misc/assignment2.right b/shell/ash_test/ash-misc/assignment2.right
index 179c71c5a..246694462 100644
--- a/shell/ash_test/ash-misc/assignment2.right
+++ b/shell/ash_test/ash-misc/assignment2.right
@@ -1,2 +1,4 @@
1./assignment2.tests: line 2: a=b: not found 1./assignment2.tests: line 2: a=b: not found
2127 2127
3./assignment2.tests: line 4: ab=c: not found
4127
diff --git a/shell/ash_test/ash-misc/assignment2.tests b/shell/ash_test/ash-misc/assignment2.tests
index f6938434c..a93a48d09 100755
--- a/shell/ash_test/ash-misc/assignment2.tests
+++ b/shell/ash_test/ash-misc/assignment2.tests
@@ -1,3 +1,5 @@
1# This must not be interpreted as an assignment 1# This must not be interpreted as an assignment
2a''=b true 2a''=b true
3echo $? 3echo $?
4a'b'=c true
5echo $?
diff --git a/shell/hush.c b/shell/hush.c
index 002140b1a..fa70e9657 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -574,15 +574,6 @@ enum {
574/* Used for initialization: o_string foo = NULL_O_STRING; */ 574/* Used for initialization: o_string foo = NULL_O_STRING; */
575#define NULL_O_STRING { NULL } 575#define NULL_O_STRING { NULL }
576 576
577#ifndef debug_printf_parse
578static const char *const assignment_flag[] ALIGN_PTR = {
579 "MAYBE_ASSIGNMENT",
580 "DEFINITELY_ASSIGNMENT",
581 "NOT_ASSIGNMENT",
582 "WORD_IS_KEYWORD",
583};
584#endif
585
586/* We almost can use standard FILE api, but we need an ability to move 577/* We almost can use standard FILE api, but we need an ability to move
587 * its fd when redirects coincide with it. No api exists for that 578 * its fd when redirects coincide with it. No api exists for that
588 * (RFE for it at https://sourceware.org/bugzilla/show_bug.cgi?id=21902). 579 * (RFE for it at https://sourceware.org/bugzilla/show_bug.cgi?id=21902).
@@ -768,9 +759,14 @@ enum {
768 MAYBE_ASSIGNMENT = 0, 759 MAYBE_ASSIGNMENT = 0,
769 DEFINITELY_ASSIGNMENT = 1, 760 DEFINITELY_ASSIGNMENT = 1,
770 NOT_ASSIGNMENT = 2, 761 NOT_ASSIGNMENT = 2,
771 /* Not an assignment, but next word may be: "if v=xyz cmd;" */
772 WORD_IS_KEYWORD = 3,
773}; 762};
763#ifndef debug_printf_parse
764static const char *const assignment_flag[] ALIGN_PTR = {
765 "MAYBE_ASSIGNMENT",
766 "DEFINITELY_ASSIGNMENT",
767 "NOT_ASSIGNMENT",
768};
769#endif
774 770
775/* On program start, environ points to initial environment. 771/* On program start, environ points to initial environment.
776 * putenv adds new pointers into it, unsetenv removes them. 772 * putenv adds new pointers into it, unsetenv removes them.
@@ -4416,16 +4412,11 @@ static int done_word(struct parse_context *ctx)
4416 4412
4417 /* If this word wasn't an assignment, next ones definitely 4413 /* If this word wasn't an assignment, next ones definitely
4418 * can't be assignments. Even if they look like ones. */ 4414 * can't be assignments. Even if they look like ones. */
4419 if (ctx->is_assignment != DEFINITELY_ASSIGNMENT 4415 if (ctx->is_assignment != DEFINITELY_ASSIGNMENT) {
4420 && ctx->is_assignment != WORD_IS_KEYWORD
4421 ) {
4422 ctx->is_assignment = NOT_ASSIGNMENT; 4416 ctx->is_assignment = NOT_ASSIGNMENT;
4423 } else { 4417 } else {
4424 if (ctx->is_assignment == DEFINITELY_ASSIGNMENT) { 4418 command->assignment_cnt++;
4425 command->assignment_cnt++; 4419 debug_printf_parse("++assignment_cnt=%d\n", command->assignment_cnt);
4426 debug_printf_parse("++assignment_cnt=%d\n", command->assignment_cnt);
4427 }
4428 debug_printf_parse("ctx->is_assignment was:'%s'\n", assignment_flag[ctx->is_assignment]);
4429 ctx->is_assignment = MAYBE_ASSIGNMENT; 4420 ctx->is_assignment = MAYBE_ASSIGNMENT;
4430 } 4421 }
4431 debug_printf_parse("ctx->is_assignment='%s'\n", assignment_flag[ctx->is_assignment]); 4422 debug_printf_parse("ctx->is_assignment='%s'\n", assignment_flag[ctx->is_assignment]);
@@ -5791,10 +5782,9 @@ static struct pipe *parse_stream(char **pstring,
5791 if (!strchr(is_special, ch)) { /* ordinary char? */ 5782 if (!strchr(is_special, ch)) { /* ordinary char? */
5792 ordinary_char: 5783 ordinary_char:
5793 o_addQchr(&ctx.word, ch); 5784 o_addQchr(&ctx.word, ch);
5794 if ((ctx.is_assignment == MAYBE_ASSIGNMENT 5785 if (ctx.is_assignment == MAYBE_ASSIGNMENT
5795 || ctx.is_assignment == WORD_IS_KEYWORD)
5796 && ch == '=' 5786 && ch == '='
5797 // && !ctx.word.has_quoted_part // unnecessary, "empty quoted str marker" trick handles this too 5787 && !ctx.word.has_quoted_part /* a''=b a'b'c=d: not assignments */
5798 && endofname(ctx.word.data)[0] == '=' 5788 && endofname(ctx.word.data)[0] == '='
5799 ) { 5789 ) {
5800 ctx.is_assignment = DEFINITELY_ASSIGNMENT; 5790 ctx.is_assignment = DEFINITELY_ASSIGNMENT;
diff --git a/shell/hush_test/hush-misc/assignment2.right b/shell/hush_test/hush-misc/assignment2.right
index 9d1860be7..5e54b408b 100644
--- a/shell/hush_test/hush-misc/assignment2.right
+++ b/shell/hush_test/hush-misc/assignment2.right
@@ -1,2 +1,4 @@
1hush: can't execute 'a=b': No such file or directory 1hush: can't execute 'a=b': No such file or directory
2127 2127
3hush: can't execute 'ab=c': No such file or directory
4127
diff --git a/shell/hush_test/hush-misc/assignment2.tests b/shell/hush_test/hush-misc/assignment2.tests
index f6938434c..a93a48d09 100755
--- a/shell/hush_test/hush-misc/assignment2.tests
+++ b/shell/hush_test/hush-misc/assignment2.tests
@@ -1,3 +1,5 @@
1# This must not be interpreted as an assignment 1# This must not be interpreted as an assignment
2a''=b true 2a''=b true
3echo $? 3echo $?
4a'b'=c true
5echo $?