diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2025-08-14 16:19:58 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2025-08-14 16:19:58 +0200 |
| commit | 6cc338010515ec4caef802a70f9f374cf98b8294 (patch) | |
| tree | 658af62d1b336265028e1edde837eed0ec328c4f | |
| parent | cad5a79bd4e8ceef4a68f1551fd2b25122bcb1c8 (diff) | |
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>
| -rw-r--r-- | shell/ash_test/ash-misc/assignment2.right | 2 | ||||
| -rwxr-xr-x | shell/ash_test/ash-misc/assignment2.tests | 2 | ||||
| -rw-r--r-- | shell/hush.c | 34 | ||||
| -rw-r--r-- | shell/hush_test/hush-misc/assignment2.right | 2 | ||||
| -rwxr-xr-x | shell/hush_test/hush-misc/assignment2.tests | 2 |
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 @@ ./assignment2.tests: line 2: a=b: not found 127 +./assignment2.tests: line 4: ab=c: not found +127 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 @@ # This must not be interpreted as an assignment a''=b true echo $? +a'b'=c true +echo $? 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 { /* Used for initialization: o_string foo = NULL_O_STRING; */ #define NULL_O_STRING { NULL } -#ifndef debug_printf_parse -static const char *const assignment_flag[] ALIGN_PTR = { - "MAYBE_ASSIGNMENT", - "DEFINITELY_ASSIGNMENT", - "NOT_ASSIGNMENT", - "WORD_IS_KEYWORD", -}; -#endif - /* We almost can use standard FILE api, but we need an ability to move * its fd when redirects coincide with it. No api exists for that * (RFE for it at https://sourceware.org/bugzilla/show_bug.cgi?id=21902). @@ -768,9 +759,14 @@ enum { MAYBE_ASSIGNMENT = 0, DEFINITELY_ASSIGNMENT = 1, NOT_ASSIGNMENT = 2, - /* Not an assignment, but next word may be: "if v=xyz cmd;" */ - WORD_IS_KEYWORD = 3, }; +#ifndef debug_printf_parse +static const char *const assignment_flag[] ALIGN_PTR = { + "MAYBE_ASSIGNMENT", + "DEFINITELY_ASSIGNMENT", + "NOT_ASSIGNMENT", +}; +#endif /* On program start, environ points to initial environment. * putenv adds new pointers into it, unsetenv removes them. @@ -4416,16 +4412,11 @@ static int done_word(struct parse_context *ctx) /* If this word wasn't an assignment, next ones definitely * can't be assignments. Even if they look like ones. */ - if (ctx->is_assignment != DEFINITELY_ASSIGNMENT - && ctx->is_assignment != WORD_IS_KEYWORD - ) { + if (ctx->is_assignment != DEFINITELY_ASSIGNMENT) { ctx->is_assignment = NOT_ASSIGNMENT; } else { - if (ctx->is_assignment == DEFINITELY_ASSIGNMENT) { - command->assignment_cnt++; - debug_printf_parse("++assignment_cnt=%d\n", command->assignment_cnt); - } - debug_printf_parse("ctx->is_assignment was:'%s'\n", assignment_flag[ctx->is_assignment]); + command->assignment_cnt++; + debug_printf_parse("++assignment_cnt=%d\n", command->assignment_cnt); ctx->is_assignment = MAYBE_ASSIGNMENT; } debug_printf_parse("ctx->is_assignment='%s'\n", assignment_flag[ctx->is_assignment]); @@ -5791,10 +5782,9 @@ static struct pipe *parse_stream(char **pstring, if (!strchr(is_special, ch)) { /* ordinary char? */ ordinary_char: o_addQchr(&ctx.word, ch); - if ((ctx.is_assignment == MAYBE_ASSIGNMENT - || ctx.is_assignment == WORD_IS_KEYWORD) + if (ctx.is_assignment == MAYBE_ASSIGNMENT && ch == '=' - // && !ctx.word.has_quoted_part // unnecessary, "empty quoted str marker" trick handles this too + && !ctx.word.has_quoted_part /* a''=b a'b'c=d: not assignments */ && endofname(ctx.word.data)[0] == '=' ) { 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 @@ hush: can't execute 'a=b': No such file or directory 127 +hush: can't execute 'ab=c': No such file or directory +127 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 @@ # This must not be interpreted as an assignment a''=b true echo $? +a'b'=c true +echo $? |
