NetBSD Problem Report #34646

From roland@roland-illig.de  Thu Sep 28 07:35:11 2006
Return-Path: <roland@roland-illig.de>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by narn.NetBSD.org (Postfix) with ESMTP id 9482063B8CA
	for <gnats-bugs@gnats.NetBSD.org>; Thu, 28 Sep 2006 07:35:11 +0000 (UTC)
Message-Id: <20060928073459.74510F35D@bacc.roland-illig.de>
Date: Thu, 28 Sep 2006 09:34:59 +0200 (CEST)
From: rillig@NetBSD.org
Reply-To: rillig@NetBSD.org
To: gnats-bugs@NetBSD.org
Subject: /bin/test does not conform to POSIX
X-Send-Pr-Version: 3.95

>Number:         34646
>Category:       standards
>Synopsis:       /bin/test does not conform to POSIX
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kre
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Sep 28 07:40:00 +0000 2006
>Closed-Date:    Thu Sep 20 21:24:19 +0000 2018
>Last-Modified:  Thu Sep 20 21:24:19 +0000 2018
>Originator:     Roland Illig
>Release:        NetBSD 3.0_STABLE
>Organization:

>Environment:


System: NetBSD bacc.roland-illig.de 3.0_STABLE NetBSD 3.0_STABLE (GENERIC) #0: Sat Jun 17 13:16:17 CEST 2006 build@baccf5ee.roland-illig.de:/home/build/3/2006-06/i386/work/sys/arch/i386/compile/GENERIC i386
Architecture: i386
Machine: i386
>Description:

http://www.opengroup.org/onlinepubs/000095399/utilities/test.html

says:

...
3 arguments:
* If $2 is a binary primary, perform the binary test of $1 and $3.
* If $1 is '!', negate the two-argument test of $2 and $3.
* [XSI] [Option Start] If $1 is '(' and $3 is ')', perform the unary
  test of $2. [Option End]
* Otherwise, produce unspecified results.

But NetBSD's /bin/test checks for the second condition before checking
the first.

>How-To-Repeat:

/bin/test ! = foo

>Fix:

>Release-Note:

>Audit-Trail:

Responsible-Changed-From-To: bin-bug-people->standards-manager
Responsible-Changed-By: dholland@NetBSD.org
Responsible-Changed-When: Mon, 14 Apr 2008 01:46:18 +0000
Responsible-Changed-Why:
standards issue


Responsible-Changed-From-To: standards-manager->kre
Responsible-Changed-By: kre@NetBSD.org
Responsible-Changed-When: Wed, 12 Sep 2018 18:22:52 +0000
Responsible-Changed-Why:
I will fix test(1) to obey the POSIX eval order rules


From: "Robert Elz" <kre@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/34646 CVS commit: src/bin/test
Date: Wed, 12 Sep 2018 23:33:31 +0000

 Module Name:	src
 Committed By:	kre
 Date:		Wed Sep 12 23:33:31 UTC 2018

 Modified Files:
 	src/bin/test: test.c

 Log Message:
 PR standards/34646

 Make test(1) always use the POSIX "number of args" evaluation rules
 when they apply.

 Only fall back to the old expression evaluation when there are more
 than 4 args, or when the args given cannot work as a test expression
 using the POSIX rules.  That is when the result is unspecified.

 Also fix old bug where a string of whitespace is considered to be a
 valid number (at least one digit is needed amongst it somewhere...)

 XXX pullup -8


 To generate a diff of this commit:
 cvs rdiff -u -r1.41 -r1.42 src/bin/test/test.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->feedback
State-Changed-By: kre@NetBSD.org
State-Changed-When: Thu, 13 Sep 2018 10:00:34 +0000
State-Changed-Why:
This should now be fixed (in HEAD) - can you confirm?

The changes will (eventually) be pulled up to -8 (the PR will
not be closed before that happens) but the request for that
will not be made until we sort out what to do with the version
of test included in /bin/sh on install media, which (being
slightly bigger now) seems to have caused (at least 1) overflow.


State-Changed-From-To: feedback->open
State-Changed-By: rillig@NetBSD.org
State-Changed-When: Thu, 20 Sep 2018 20:14:26 +0000
State-Changed-Why:
Works like a charm. I only did a few tests though, since I don't have an
automatic test suite at hand.


State-Changed-From-To: open->closed
State-Changed-By: kre@NetBSD.org
State-Changed-When: Thu, 20 Sep 2018 21:24:19 +0000
State-Changed-Why:
Thanks, general operation of test is fairly heavily tested by
the general (shell based) ATF tests, as it is a part of essentially
all of those - we could do with some better testing of the corner
cases though.


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.43 2018/01/16 07:36:43 maya Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2017 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.