Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 20 Jul 2002 00:06:00 -0700 (PDT)
From:      Landon Fuller <landonf@opendarwin.org>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   bin/40801: touch(1) attempts to open a directory O_RDWR
Message-ID:  <200207200706.g6K760mE016595@www.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         40801
>Category:       bin
>Synopsis:       touch(1) attempts to open a directory O_RDWR
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Jul 20 00:10:05 PDT 2002
>Closed-Date:
>Last-Modified:
>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:
>Unformatted:

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200207200706.g6K760mE016595>