summaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>2020-01-28 14:08:00 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2020-02-10 09:42:43 +0100
commit7b95857a7ad911e698dc18261deceffdfd7d9fdb (patch)
tree84389bcd212cd395f68c890388a82cd4d5a990e4 /commands
parent6e7f99f26673e932a7c6e45a31727d4a82dd2c8c (diff)
downloadbarebox-7b95857a7ad911e698dc18261deceffdfd7d9fdb.tar.gz
barebox-7b95857a7ad911e698dc18261deceffdfd7d9fdb.tar.xz
commands/test: Improve option parsing to handle "]" less special
Testing for *ap[1] != ']' is bogus during option processing. Instead test if there are options left to be processed. This fixes the return value for e.g. test -z ']lala' Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands')
-rw-r--r--commands/test.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/commands/test.c b/commands/test.c
index ab108fc845..9070e49074 100644
--- a/commands/test.c
+++ b/commands/test.c
@@ -129,8 +129,11 @@ static int do_test(int argc, char *argv[])
case OPT_ZERO:
case OPT_NONZERO:
adv = 2;
+ if (left < 2)
+ break;
zero = 1;
- if (ap[1] && *ap[1] != ']' && strlen(ap[1]))
+
+ if (strlen(ap[1]))
zero = 0;
expr = (opt == OPT_ZERO) ? zero : !zero;
@@ -141,7 +144,9 @@ static int do_test(int argc, char *argv[])
case OPT_EXISTS:
case OPT_SYMBOLIC_LINK:
adv = 2;
- if (ap[1] && *ap[1] != ']' && strlen(ap[1])) {
+ if (left < 2)
+ break;
+ if (strlen(ap[1])) {
expr = (opt == OPT_SYMBOLIC_LINK ? lstat : stat)(ap[1], &statbuf);
if (expr < 0) {
expr = 0;
@@ -170,10 +175,8 @@ static int do_test(int argc, char *argv[])
/* three argument options */
default:
adv = 3;
- if (left < 3) {
- expr = 1;
+ if (left < 3)
break;
- }
a = simple_strtol(ap[0], NULL, 0);
b = simple_strtol(ap[2], NULL, 0);