dash.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [BUG] test: -gt: unexpected operator
@ 2015-07-12 23:30 Martijn Dekker
  2015-07-13  6:06 ` Herbert Xu
  0 siblings, 1 reply; 3+ messages in thread
From: Martijn Dekker @ 2015-07-12 23:30 UTC (permalink / raw)
  To: dash

I found a bug in dash that affects checking the exit status of '[' or
'test' for failure.

After feeding an illegal number to 'test -t', 'test' will not accept any
operator (or at least not -gt or -lt) for the next invocation.

Confirmed in dash 0.5.7, 0.5.8 and current git version.

$ [ -t 12323454234578326584376438 ]
src/dash: 7: [: Illegal number: 12323454234578326584376438
$ [ "$?" -gt 1 ] && echo error
src/dash: 8: [: -gt: unexpected operator
$ [ "$?" -gt 1 ] && echo error
error
$ test -t 12323454234578326584376438
src/dash: 10: test: Illegal number: 12323454234578326584376438
$ test "$?" -gt 1 && echo error
src/dash: 11: test: -gt: unexpected operator
$ test "$?" -gt 1 && echo error
error
$ test -t 12323454234578326584376438
src/dash: 13: test: Illegal number: 12323454234578326584376438
$ test 2 -gt 1
src/dash: 14: test: -gt: unexpected operator
$ test 2 -gt 1
$ test -t 12323454234578326584376438
src/dash: 16: test: Illegal number: 12323454234578326584376438
$ test 2 -lt 1
src/dash: 17: test: -lt: unexpected operator
$ test 2 -lt 1
$

Thanks,

- Martijn

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [BUG] test: -gt: unexpected operator
  2015-07-12 23:30 [BUG] test: -gt: unexpected operator Martijn Dekker
@ 2015-07-13  6:06 ` Herbert Xu
  2015-07-13  7:17   ` Martijn Dekker
  0 siblings, 1 reply; 3+ messages in thread
From: Herbert Xu @ 2015-07-13  6:06 UTC (permalink / raw)
  To: Martijn Dekker; +Cc: dash

Martijn Dekker <martijn@inlv.org> wrote:
> I found a bug in dash that affects checking the exit status of '[' or
> 'test' for failure.
> 
> After feeding an illegal number to 'test -t', 'test' will not accept any
> operator (or at least not -gt or -lt) for the next invocation.
> 
> Confirmed in dash 0.5.7, 0.5.8 and current git version.

Thanks for the report.  Does this patch help?

---8<---
Subject: builtin: Reset t_wp_op in testcmd

The global variable t_wp_op needs to be reset every time testcmd
is called or it may cause incorrect parsing of the arguments.

Reported-by: Martijn Dekker <martijn@inlv.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

diff --git a/src/bltin/test.c b/src/bltin/test.c
index bab9a1f..58c05fe 100644
--- a/src/bltin/test.c
+++ b/src/bltin/test.c
@@ -193,6 +193,8 @@ testcmd(int argc, char **argv)
 		argv[argc] = NULL;
 	}
 
+	t_wp_op = NULL;
+
 recheck:
 	argv++;
 	argc--;
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [BUG] test: -gt: unexpected operator
  2015-07-13  6:06 ` Herbert Xu
@ 2015-07-13  7:17   ` Martijn Dekker
  0 siblings, 0 replies; 3+ messages in thread
From: Martijn Dekker @ 2015-07-13  7:17 UTC (permalink / raw)
  To: Herbert Xu; +Cc: dash

Herbert Xu schreef op 13-07-15 om 08:06:
> Thanks for the report.  Does this patch help?

Yes, it does.

Thanks,

- M.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-07-13  7:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-12 23:30 [BUG] test: -gt: unexpected operator Martijn Dekker
2015-07-13  6:06 ` Herbert Xu
2015-07-13  7:17   ` Martijn Dekker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).