klibc-bot for Herbert Xu
2020-Mar-28 21:48 UTC
[klibc] [klibc:update-dash] dash: [BUILTIN] Correctly handle test ! ! = !
Commit-ID: b72377e6b73676c43bd0cff5eb202694a9c2b4ea Gitweb: http://git.kernel.org/?p=libs/klibc/klibc.git;a=commit;h=b72377e6b73676c43bd0cff5eb202694a9c2b4ea Author: Herbert Xu <herbert at gondor.apana.org.au> AuthorDate: Sun, 28 Sep 2014 18:40:18 +0800 Committer: Ben Hutchings <ben at decadent.org.uk> CommitDate: Sat, 28 Mar 2020 21:42:54 +0000 [klibc] dash: [BUILTIN] Correctly handle test ! ! = ! [ dash commit 4f7e4c8201e580b9d31c09d8a484741072033c01 ] This patch adds a special case in testcmd for the 4-argument expression beginning with a !. Without this ! ! = ! is deemed a syntax error, which breaks POSIX. Note that this special case does not extend down into subexpressions so if ! ! = ! is used inside parentheses then a syntax error will still occur as before. Signed-off-by: Herbert Xu <herbert at gondor.apana.org.au> Signed-off-by: Ben Hutchings <ben at decadent.org.uk> --- usr/dash/bltin/test.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/usr/dash/bltin/test.c b/usr/dash/bltin/test.c index baa91a57..458e9f55 100644 --- a/usr/dash/bltin/test.c +++ b/usr/dash/bltin/test.c @@ -177,7 +177,7 @@ testcmd(int argc, char **argv) { const struct t_op *op; enum token n; - int res; + int res = 1; if (*argv[0] == '[') { if (*argv[--argc] != ']') @@ -185,11 +185,12 @@ testcmd(int argc, char **argv) argv[argc] = NULL; } +recheck: argv++; argc--; if (argc < 1) - return 1; + return res; /* * POSIX prescriptions: he who wrote this deserves the Nobel @@ -209,6 +210,9 @@ testcmd(int argc, char **argv) argv[--argc] = NULL; argv++; argc--; + } else if (!strcmp(argv[0], "!")) { + res = 0; + goto recheck; } } @@ -216,7 +220,7 @@ testcmd(int argc, char **argv) eval: t_wp = argv; - res = !oexpr(n); + res ^= oexpr(n); argv = t_wp; if (argv[0] != NULL && argv[1] != NULL)
Possibly Parallel Threads
- [klibc:update-dash] [BUILTIN] Correctly handle test ! ! = !
- [klibc:update-dash] [BUILTIN] Fixed argument parsing crash in test
- [klibc:update-dash] dash: [BUILTIN] Fixed argument parsing crash in test
- [klibc:update-dash] builtin: Reset t_wp_op in testcmd
- [klibc:update-dash] dash: builtin: Reset t_wp_op in testcmd