From nobody@FreeBSD.org  Sat Jul 20 00:06:00 2002
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id DA0E837B400
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 20 Jul 2002 00:06:00 -0700 (PDT)
Received: from www.freebsd.org (www.FreeBSD.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 9EBE843E64
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 20 Jul 2002 00:06:00 -0700 (PDT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.12.4/8.12.4) with ESMTP id g6K760OT016596
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 20 Jul 2002 00:06:00 -0700 (PDT)
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.12.4/8.12.4/Submit) id g6K760mE016595;
	Sat, 20 Jul 2002 00:06:00 -0700 (PDT)
Message-Id: <200207200706.g6K760mE016595@www.freebsd.org>
Date: Sat, 20 Jul 2002 00:06:00 -0700 (PDT)
From: Landon Fuller <landonf@opendarwin.org>
To: freebsd-gnats-submit@FreeBSD.org
Subject: touch(1) attempts to open a directory O_RDWR
X-Send-Pr-Version: www-1.0

>Number:         40801
>Category:       bin
>Synopsis:       touch(1) attempts to open a directory O_RDWR
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    eric
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Jul 20 00:10:05 PDT 2002
>Closed-Date:    Tue Jul 23 03:12:42 PDT 2002
>Last-Modified:  Tue Jul 23 03:12:42 PDT 2002
>Originator:     Landon Fuller
>Release:        FreeBSD 4.5-RELEASE i386
>Organization:
Apple Computer, Inc
>Environment:
FreeBSD machine.apple.com 4.5-RELEASE FreeBSD 4.5-RELEASE #0: Mon Jan 28 14:31:56 GMT 2002     murray@builder.freebsdmall.com:/usr/src/sys/compile/GENERIC  i386
>Description:
touch attempts to open directories O_RDWR in a last ditch effort to update the the directories' modification time.

This results in the following:
> touch /etc
touch: /etc: Is a directory

Should be:
touch /etc
touch: /etc: Permission denied
>How-To-Repeat:
'touch' a directory to which you not have write permission
>Fix:
http://public.boredom.org/~swift/code/touch.diff

Index: touch.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/touch/touch.c,v
retrieving revision 1.16
diff -u -d -w -b -r1.16 touch.c
--- touch.c     2002/03/22 01:42:36     1.16
+++ touch.c     2002/07/20 06:58:22
@@ -186,8 +186,11 @@
                        continue;

                /* Try reading/writing. */
-               if (rw(*argv, &sb, fflag))
+               if (!S_ISLNK(sb.st_mode) && !S_ISDIR(sb.st_mode) &&
+                   rw(*argv, &sb, fflag))
                        rval = 1;
+               else
+                       warn("%s", *argv);
        }
        exit(rval);
 }
@@ -312,8 +315,8 @@
        int fd, needed_chmod, rval;
        u_char byte;

-       /* Try regular files and directories. */
-       if (!S_ISREG(sbp->st_mode) && !S_ISDIR(sbp->st_mode)) {
+       /* Try regular files. */
+       if (!S_ISREG(sbp->st_mode)) {
                warnx("%s: %s", fname, strerror(EFTYPE));
                return (1);
        }
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->eric 
Responsible-Changed-By: eric 
Responsible-Changed-When: Sat Jul 20 00:15:03 PDT 2002 
Responsible-Changed-Why:  

http://www.freebsd.org/cgi/query-pr.cgi?pr=40801 
State-Changed-From-To: open->closed 
State-Changed-By: eric 
State-Changed-When: Tue Jul 23 03:11:57 PDT 2002 
State-Changed-Why:  
committed 

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