From pirzyk@freebsd.org  Tue Mar 22 15:58:35 2011
Return-Path: <pirzyk@freebsd.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id B1DF1106564A
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 22 Mar 2011 15:58:35 +0000 (UTC)
	(envelope-from pirzyk@freebsd.org)
Received: from zoot.intenex.net (zoot.intenex.net [216.93.182.12])
	by mx1.freebsd.org (Postfix) with ESMTP id 9DAF38FC0C
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 22 Mar 2011 15:58:35 +0000 (UTC)
Received: from [192.168.218.46] (c1fw238.constantcontact.com [205.207.104.238])
	(authenticated bits=0)
	by zoot.intenex.net (8.13.8/8.13.8) with ESMTP id p2MFwQbt019747
	(version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO)
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 22 Mar 2011 10:58:27 -0500
Message-Id: <93611D77-F2D7-4E2D-8839-35A1C72C2F26@freebsd.org>
Date: Tue, 22 Mar 2011 11:58:19 -0400
From: Jim Pirzyk <pirzyk@freebsd.org>
To: FreeBSD-gnats-submit@freebsd.org
Subject: '/bin/test -d' fails to report syntax error

>Number:         155786
>Category:       bin
>Synopsis:       [patch] test(1): '/bin/test -d' fails to report syntax error
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    jilles
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Mar 22 16:00:05 UTC 2011
>Closed-Date:    Sun Mar 02 22:07:57 UTC 2014
>Last-Modified:  Sun Mar 02 22:07:57 UTC 2014
>Originator:     Jim Pirzyk
>Release:        FreeBSD 8.2-RELEASE amd64
>Organization:
=09
>Environment:
System: FreeBSD freebsd.home.pirzyk.org 8.2-RELEASE FreeBSD 8.2-RELEASE #0: Thu Feb 17 02:41:51 UTC 2011 root@mason.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC amd64

>Description:
	Running the command '/bin/test -d' does not report a syntax error, like it
	does on Solaris systems.

>How-To-Repeat:
	FreeBSD $ /bin/test -d; echo $?
	0

	Solaris $ /bin/test -d ; echo $?
	ksh: test: argument expected
	2

>Fix:

--- ./bin/test/test.c.orig	2011-02-27 14:02:10.000000000 -0500
+++ ./bin/test/test.c	2011-03-22 11:35:03.000000000 -0400
@@ -424,12 +424,12 @@
 	}
 	while (op->op_text) {
 		if (strcmp(s, op->op_text) == 0) {
+			t_wp_op = op;
 			if (((op->op_type == UNOP || op->op_type == BUNOP)
 						&& isunopoperand()) ||
 			    (op->op_num == LPAREN && islparenoperand()) ||
 			    (op->op_num == RPAREN && isrparenoperand()))
-				break;
-			t_wp_op = op;
+				syntax(t_wp_op->op_text, "argument expected");
 			return op->op_num;
 		}
 		op++;
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: jilles 
State-Changed-When: Sun Mar 2 22:06:16 UTC 2014 
State-Changed-Why:  
This is not a bug. 
'/bin/test -d' is not an error and is supposed to return true (0). 

This is because '-d' in 'test -d' is a string operand that is tested 
for non-emptiness. In the man page test(1): 

string        True if string is not the null string. 

In the POSIX specification (SUSv4+TC1), also look for the algorithm for 
resolving the ambiguities in test: 

> 1 argument: Exit true (0) if $1 is not null; otherwise, exit false. 


Responsible-Changed-From-To: freebsd-bugs->jilles 
Responsible-Changed-By: jilles 
Responsible-Changed-When: Sun Mar 2 22:06:16 UTC 2014 
Responsible-Changed-Why:  
Track replies. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=155786 
>Unformatted:
